@@ -14,1316 +14,1316 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Main { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var file |
|
| 19 | - * Reference to the main plugin file |
|
| 20 | - */ |
|
| 21 | - private $file; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var $_instance reference to the the main and only instance of the Sensei class. |
|
| 25 | - * @since 1.8.0 |
|
| 26 | - */ |
|
| 27 | - protected static $_instance = null; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Main reference to the plugins current version |
|
| 31 | - */ |
|
| 32 | - public $version; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Public token, referencing for the text domain. |
|
| 36 | - */ |
|
| 37 | - public $token = 'woothemes-sensei'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Plugin url and path for use when access resources. |
|
| 41 | - */ |
|
| 42 | - public $plugin_url; |
|
| 43 | - public $plugin_path; |
|
| 44 | - public $template_url; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var WooThemes_Sensei_PostTypes |
|
| 48 | - * All Sensei sub classes. Currently used to access functionality contained within |
|
| 49 | - * within Sensei sub classes e.g. Sensei()->course->all_courses() |
|
| 50 | - */ |
|
| 51 | - public $post_types; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var WooThemes_Sensei_Settings |
|
| 55 | - */ |
|
| 56 | - public $settings; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var WooThemes_Sensei_Course_Results |
|
| 60 | - */ |
|
| 61 | - public $course_results; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var WooThemes_Sensei_Course |
|
| 65 | - */ |
|
| 66 | - public $course; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var WooThemes_Sensei_Lesson |
|
| 70 | - */ |
|
| 71 | - public $lesson; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var WooThemes_Sensei_Quiz |
|
| 75 | - */ |
|
| 76 | - public $quiz; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @var WooThemes_Sensei_Question |
|
| 80 | - */ |
|
| 81 | - public $question; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @var WooThemes_Sensei_Admin |
|
| 85 | - */ |
|
| 86 | - public $admin; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @var WooThemes_Sensei_Frontend |
|
| 90 | - */ |
|
| 91 | - public $frontend; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @var String |
|
| 95 | - */ |
|
| 96 | - public $notice; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @var WooThemes_Sensei_Grading |
|
| 100 | - */ |
|
| 101 | - public $grading; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @var WooThemes_Sensei_Emails |
|
| 105 | - */ |
|
| 106 | - public $emails; |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @var WooThemes_Sensei_Learner_Profiles |
|
| 110 | - */ |
|
| 111 | - public $learner_profiles; |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @var Sensei_Teacher |
|
| 115 | - */ |
|
| 116 | - public $teacher; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @var WooThemes_Sensei_Learners |
|
| 120 | - */ |
|
| 121 | - public $learners; |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @var array |
|
| 125 | - * Global instance for access to the permissions message shown |
|
| 126 | - * when users do not have the right privileges to access resources. |
|
| 127 | - */ |
|
| 128 | - public $permissions_message; |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @var Sensei_Core_Modules Sensei Modules functionality |
|
| 132 | - */ |
|
| 133 | - public $modules; |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @var Sensei_Analysis |
|
| 137 | - */ |
|
| 138 | - public $analysis; |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Constructor method. |
|
| 142 | - * @param string $file The base file of the plugin. |
|
| 143 | - * @since 1.0.0 |
|
| 144 | - */ |
|
| 145 | - public function __construct ( $file ) { |
|
| 146 | - |
|
| 147 | - // Setup object data |
|
| 148 | - $this->file = $file; |
|
| 149 | - $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
| 150 | - $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
| 151 | - $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
| 152 | - $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
| 153 | - |
|
| 154 | - // Initialize the core Sensei functionality |
|
| 155 | - $this->init(); |
|
| 17 | + /** |
|
| 18 | + * @var file |
|
| 19 | + * Reference to the main plugin file |
|
| 20 | + */ |
|
| 21 | + private $file; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var $_instance reference to the the main and only instance of the Sensei class. |
|
| 25 | + * @since 1.8.0 |
|
| 26 | + */ |
|
| 27 | + protected static $_instance = null; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Main reference to the plugins current version |
|
| 31 | + */ |
|
| 32 | + public $version; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Public token, referencing for the text domain. |
|
| 36 | + */ |
|
| 37 | + public $token = 'woothemes-sensei'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Plugin url and path for use when access resources. |
|
| 41 | + */ |
|
| 42 | + public $plugin_url; |
|
| 43 | + public $plugin_path; |
|
| 44 | + public $template_url; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var WooThemes_Sensei_PostTypes |
|
| 48 | + * All Sensei sub classes. Currently used to access functionality contained within |
|
| 49 | + * within Sensei sub classes e.g. Sensei()->course->all_courses() |
|
| 50 | + */ |
|
| 51 | + public $post_types; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var WooThemes_Sensei_Settings |
|
| 55 | + */ |
|
| 56 | + public $settings; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var WooThemes_Sensei_Course_Results |
|
| 60 | + */ |
|
| 61 | + public $course_results; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var WooThemes_Sensei_Course |
|
| 65 | + */ |
|
| 66 | + public $course; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var WooThemes_Sensei_Lesson |
|
| 70 | + */ |
|
| 71 | + public $lesson; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var WooThemes_Sensei_Quiz |
|
| 75 | + */ |
|
| 76 | + public $quiz; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @var WooThemes_Sensei_Question |
|
| 80 | + */ |
|
| 81 | + public $question; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @var WooThemes_Sensei_Admin |
|
| 85 | + */ |
|
| 86 | + public $admin; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @var WooThemes_Sensei_Frontend |
|
| 90 | + */ |
|
| 91 | + public $frontend; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @var String |
|
| 95 | + */ |
|
| 96 | + public $notice; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @var WooThemes_Sensei_Grading |
|
| 100 | + */ |
|
| 101 | + public $grading; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @var WooThemes_Sensei_Emails |
|
| 105 | + */ |
|
| 106 | + public $emails; |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @var WooThemes_Sensei_Learner_Profiles |
|
| 110 | + */ |
|
| 111 | + public $learner_profiles; |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @var Sensei_Teacher |
|
| 115 | + */ |
|
| 116 | + public $teacher; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @var WooThemes_Sensei_Learners |
|
| 120 | + */ |
|
| 121 | + public $learners; |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @var array |
|
| 125 | + * Global instance for access to the permissions message shown |
|
| 126 | + * when users do not have the right privileges to access resources. |
|
| 127 | + */ |
|
| 128 | + public $permissions_message; |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @var Sensei_Core_Modules Sensei Modules functionality |
|
| 132 | + */ |
|
| 133 | + public $modules; |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @var Sensei_Analysis |
|
| 137 | + */ |
|
| 138 | + public $analysis; |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Constructor method. |
|
| 142 | + * @param string $file The base file of the plugin. |
|
| 143 | + * @since 1.0.0 |
|
| 144 | + */ |
|
| 145 | + public function __construct ( $file ) { |
|
| 146 | + |
|
| 147 | + // Setup object data |
|
| 148 | + $this->file = $file; |
|
| 149 | + $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
| 150 | + $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
| 151 | + $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
| 152 | + $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
| 153 | + |
|
| 154 | + // Initialize the core Sensei functionality |
|
| 155 | + $this->init(); |
|
| 156 | 156 | |
| 157 | - // Installation |
|
| 158 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 157 | + // Installation |
|
| 158 | + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 159 | 159 | |
| 160 | - // Run this on activation. |
|
| 161 | - register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
| 160 | + // Run this on activation. |
|
| 161 | + register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
| 162 | 162 | |
| 163 | - // Setup post types. |
|
| 164 | - $this->post_types = new Sensei_PostTypes(); |
|
| 165 | - $this->post_types->token = 'woothemes-sensei-posttypes'; |
|
| 166 | - |
|
| 167 | - // Lad the updates class |
|
| 168 | - $this->updates = new WooThemes_Sensei_Updates( $this ); |
|
| 169 | - |
|
| 170 | - // Setup settings screen. |
|
| 171 | - $this->settings = new Sensei_Settings(); |
|
| 172 | - $this->settings->token = 'woothemes-sensei-settings'; |
|
| 173 | - |
|
| 174 | - // Setup Admin Settings data |
|
| 175 | - if ( is_admin() ) { |
|
| 176 | - |
|
| 177 | - $this->settings->has_tabs = true; |
|
| 178 | - $this->settings->name = __( 'Sensei Settings', 'woothemes-sensei' ); |
|
| 179 | - $this->settings->menu_label = __( 'Settings', 'woothemes-sensei' ); |
|
| 180 | - $this->settings->page_slug = 'woothemes-sensei-settings'; |
|
| 163 | + // Setup post types. |
|
| 164 | + $this->post_types = new Sensei_PostTypes(); |
|
| 165 | + $this->post_types->token = 'woothemes-sensei-posttypes'; |
|
| 166 | + |
|
| 167 | + // Lad the updates class |
|
| 168 | + $this->updates = new WooThemes_Sensei_Updates( $this ); |
|
| 169 | + |
|
| 170 | + // Setup settings screen. |
|
| 171 | + $this->settings = new Sensei_Settings(); |
|
| 172 | + $this->settings->token = 'woothemes-sensei-settings'; |
|
| 173 | + |
|
| 174 | + // Setup Admin Settings data |
|
| 175 | + if ( is_admin() ) { |
|
| 176 | + |
|
| 177 | + $this->settings->has_tabs = true; |
|
| 178 | + $this->settings->name = __( 'Sensei Settings', 'woothemes-sensei' ); |
|
| 179 | + $this->settings->menu_label = __( 'Settings', 'woothemes-sensei' ); |
|
| 180 | + $this->settings->page_slug = 'woothemes-sensei-settings'; |
|
| 181 | 181 | |
| 182 | - } // End If Statement |
|
| 182 | + } // End If Statement |
|
| 183 | 183 | |
| 184 | - $this->settings->setup_settings(); |
|
| 185 | - $this->settings->get_settings(); |
|
| 184 | + $this->settings->setup_settings(); |
|
| 185 | + $this->settings->get_settings(); |
|
| 186 | 186 | |
| 187 | - // Load Course Results Class |
|
| 188 | - $this->course_results = new Sensei_Course_Results(); |
|
| 189 | - $this->course_results->token = $this->token; |
|
| 187 | + // Load Course Results Class |
|
| 188 | + $this->course_results = new Sensei_Course_Results(); |
|
| 189 | + $this->course_results->token = $this->token; |
|
| 190 | 190 | |
| 191 | - // Load the teacher role |
|
| 192 | - $this->teacher = new Sensei_Teacher(); |
|
| 191 | + // Load the teacher role |
|
| 192 | + $this->teacher = new Sensei_Teacher(); |
|
| 193 | 193 | |
| 194 | - // Add the Course class |
|
| 195 | - $this->course = $this->post_types->course; |
|
| 194 | + // Add the Course class |
|
| 195 | + $this->course = $this->post_types->course; |
|
| 196 | 196 | |
| 197 | - // Add the lesson class |
|
| 198 | - $this->lesson = $this->post_types->lesson; |
|
| 197 | + // Add the lesson class |
|
| 198 | + $this->lesson = $this->post_types->lesson; |
|
| 199 | 199 | |
| 200 | - // Add the question class |
|
| 201 | - $this->question = $this->post_types->question; |
|
| 200 | + // Add the question class |
|
| 201 | + $this->question = $this->post_types->question; |
|
| 202 | 202 | |
| 203 | - //Add the quiz class |
|
| 204 | - $this->quiz = $this->post_types->quiz; |
|
| 203 | + //Add the quiz class |
|
| 204 | + $this->quiz = $this->post_types->quiz; |
|
| 205 | 205 | |
| 206 | - // load the modules class |
|
| 207 | - add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
| 206 | + // load the modules class |
|
| 207 | + add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
| 208 | 208 | |
| 209 | - // Load Learner Management Functionality |
|
| 210 | - $this->learners = new Sensei_Learners( $file ); |
|
| 211 | - $this->learners->token = $this->token; |
|
| 209 | + // Load Learner Management Functionality |
|
| 210 | + $this->learners = new Sensei_Learners( $file ); |
|
| 211 | + $this->learners->token = $this->token; |
|
| 212 | 212 | |
| 213 | - // Differentiate between administration and frontend logic. |
|
| 214 | - if ( is_admin() ) { |
|
| 213 | + // Differentiate between administration and frontend logic. |
|
| 214 | + if ( is_admin() ) { |
|
| 215 | 215 | |
| 216 | - // Load Admin Welcome class |
|
| 217 | - new Sensei_Welcome(); |
|
| 216 | + // Load Admin Welcome class |
|
| 217 | + new Sensei_Welcome(); |
|
| 218 | 218 | |
| 219 | - // Load Admin Class |
|
| 220 | - $this->admin = new Sensei_Admin( $file ); |
|
| 221 | - $this->admin->token = $this->token; |
|
| 219 | + // Load Admin Class |
|
| 220 | + $this->admin = new Sensei_Admin( $file ); |
|
| 221 | + $this->admin->token = $this->token; |
|
| 222 | 222 | |
| 223 | - // Load Analysis Reports |
|
| 224 | - $this->analysis = new Sensei_Analysis( $file ); |
|
| 225 | - $this->analysis->token = $this->token; |
|
| 223 | + // Load Analysis Reports |
|
| 224 | + $this->analysis = new Sensei_Analysis( $file ); |
|
| 225 | + $this->analysis->token = $this->token; |
|
| 226 | 226 | |
| 227 | 227 | |
| 228 | - } else { |
|
| 228 | + } else { |
|
| 229 | 229 | |
| 230 | - // Load Frontend Class |
|
| 231 | - $this->frontend = new Sensei_Frontend(); |
|
| 232 | - $this->frontend->token = $this->token; |
|
| 233 | - $this->frontend->init(); |
|
| 230 | + // Load Frontend Class |
|
| 231 | + $this->frontend = new Sensei_Frontend(); |
|
| 232 | + $this->frontend->token = $this->token; |
|
| 233 | + $this->frontend->init(); |
|
| 234 | 234 | |
| 235 | - // Load notice Class |
|
| 236 | - $this->notices = new Sensei_Notices(); |
|
| 235 | + // Load notice Class |
|
| 236 | + $this->notices = new Sensei_Notices(); |
|
| 237 | 237 | |
| 238 | - } |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - // Load Grading Functionality |
|
| 241 | - $this->grading = new Sensei_Grading( $file ); |
|
| 242 | - $this->grading->token = $this->token; |
|
| 240 | + // Load Grading Functionality |
|
| 241 | + $this->grading = new Sensei_Grading( $file ); |
|
| 242 | + $this->grading->token = $this->token; |
|
| 243 | 243 | |
| 244 | - // Load Email Class |
|
| 245 | - $this->emails = new Sensei_Emails( $file ); |
|
| 246 | - $this->emails->token = $this->token; |
|
| 244 | + // Load Email Class |
|
| 245 | + $this->emails = new Sensei_Emails( $file ); |
|
| 246 | + $this->emails->token = $this->token; |
|
| 247 | 247 | |
| 248 | - // Load Learner Profiles Class |
|
| 249 | - $this->learner_profiles = new Sensei_Learner_Profiles(); |
|
| 250 | - $this->learner_profiles->token = $this->token; |
|
| 248 | + // Load Learner Profiles Class |
|
| 249 | + $this->learner_profiles = new Sensei_Learner_Profiles(); |
|
| 250 | + $this->learner_profiles->token = $this->token; |
|
| 251 | 251 | |
| 252 | - // Image Sizes |
|
| 253 | - $this->init_image_sizes(); |
|
| 252 | + // Image Sizes |
|
| 253 | + $this->init_image_sizes(); |
|
| 254 | 254 | |
| 255 | - // Force WooCommerce Required Settings |
|
| 256 | - $this->set_woocommerce_functionality(); |
|
| 257 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 258 | - add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
| 255 | + // Force WooCommerce Required Settings |
|
| 256 | + $this->set_woocommerce_functionality(); |
|
| 257 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 258 | + add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
| 259 | 259 | |
| 260 | - // WooCommerce Payment Actions |
|
| 261 | - add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 262 | - add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 263 | - add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 264 | - add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 265 | - add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 266 | - add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 267 | - add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) ); |
|
| 260 | + // WooCommerce Payment Actions |
|
| 261 | + add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 262 | + add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 263 | + add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 264 | + add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 265 | + add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 266 | + add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 267 | + add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) ); |
|
| 268 | 268 | |
| 269 | - // WooCommerce Subscriptions Actions |
|
| 270 | - add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 ); |
|
| 271 | - add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 272 | - add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 273 | - add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 274 | - add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 269 | + // WooCommerce Subscriptions Actions |
|
| 270 | + add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 ); |
|
| 271 | + add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 272 | + add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 273 | + add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 274 | + add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 275 | 275 | |
| 276 | - // Add Email link to course orders |
|
| 277 | - add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 ); |
|
| 276 | + // Add Email link to course orders |
|
| 277 | + add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 ); |
|
| 278 | 278 | |
| 279 | - // Filter comment counts |
|
| 280 | - add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
| 279 | + // Filter comment counts |
|
| 280 | + add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
| 281 | 281 | |
| 282 | - add_action( 'body_class', array( $this, 'body_class' ) ); |
|
| 282 | + add_action( 'body_class', array( $this, 'body_class' ) ); |
|
| 283 | 283 | |
| 284 | - // Check for and activate JetPack LaTeX support |
|
| 285 | - add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
| 284 | + // Check for and activate JetPack LaTeX support |
|
| 285 | + add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
| 286 | 286 | |
| 287 | - // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
|
| 288 | - add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
| 287 | + // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
|
| 288 | + add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
| 289 | 289 | |
| 290 | - } // End __construct() |
|
| 290 | + } // End __construct() |
|
| 291 | 291 | |
| 292 | - /** |
|
| 293 | - * Load the foundations of Sensei. |
|
| 294 | - * @since 1.9.0 |
|
| 295 | - */ |
|
| 296 | - protected function init(){ |
|
| 292 | + /** |
|
| 293 | + * Load the foundations of Sensei. |
|
| 294 | + * @since 1.9.0 |
|
| 295 | + */ |
|
| 296 | + protected function init(){ |
|
| 297 | 297 | |
| 298 | - // Localisation |
|
| 299 | - $this->load_plugin_textdomain(); |
|
| 300 | - add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
| 298 | + // Localisation |
|
| 299 | + $this->load_plugin_textdomain(); |
|
| 300 | + add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
| 301 | 301 | |
| 302 | - // load the shortcode loader into memory, so as to listen to all for |
|
| 303 | - // all shortcodes on the front end |
|
| 304 | - new Sensei_Shortcode_Loader(); |
|
| 302 | + // load the shortcode loader into memory, so as to listen to all for |
|
| 303 | + // all shortcodes on the front end |
|
| 304 | + new Sensei_Shortcode_Loader(); |
|
| 305 | 305 | |
| 306 | - } |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - /** |
|
| 309 | - * This function is linked into the activation |
|
| 310 | - * hook to reset flush the urls to ensure Sensei post types show up. |
|
| 311 | - * |
|
| 312 | - * @since 1.9.0 |
|
| 313 | - * |
|
| 314 | - * @param $plugin |
|
| 315 | - */ |
|
| 316 | - public static function activation_flush_rules( $plugin ){ |
|
| 317 | - |
|
| 318 | - if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
| 319 | - |
|
| 320 | - flush_rewrite_rules(true); |
|
| 321 | - |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Global Sensei Instance |
|
| 328 | - * |
|
| 329 | - * Ensure that only one instance of the main Sensei class can be loaded. |
|
| 330 | - * |
|
| 331 | - * @since 1.8.0 |
|
| 332 | - * @static |
|
| 333 | - * @see WC() |
|
| 334 | - * @return WooThemes_Sensei Instance. |
|
| 335 | - */ |
|
| 336 | - public static function instance() { |
|
| 337 | - |
|
| 338 | - if ( is_null( self::$_instance ) ) { |
|
| 339 | - |
|
| 340 | - //Sensei requires a reference to the main Sensei plugin file |
|
| 341 | - $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
| 342 | - |
|
| 343 | - self::$_instance = new self( $sensei_main_plugin_file ); |
|
| 344 | - |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - return self::$_instance; |
|
| 348 | - |
|
| 349 | - } // end instance() |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * Cloning is forbidden. |
|
| 353 | - * @since 1.8.0 |
|
| 354 | - */ |
|
| 355 | - public function __clone() { |
|
| 356 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Unserializing instances of this class is forbidden. |
|
| 361 | - * @since 1.8.0 |
|
| 362 | - */ |
|
| 363 | - public function __wakeup() { |
|
| 364 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * Run Sensei updates. |
|
| 369 | - * @access public |
|
| 370 | - * @since 1.1.0 |
|
| 371 | - * @return void |
|
| 372 | - */ |
|
| 373 | - public function run_updates() { |
|
| 374 | - // Run updates if administrator |
|
| 375 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
| 376 | - |
|
| 377 | - $this->updates->update(); |
|
| 378 | - |
|
| 379 | - } // End If Statement |
|
| 380 | - } // End run_updates() |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Setup required WooCommerce settings. |
|
| 384 | - * @access public |
|
| 385 | - * @since 1.1.0 |
|
| 386 | - * @return void |
|
| 387 | - */ |
|
| 388 | - public function set_woocommerce_functionality() { |
|
| 389 | - // Disable guest checkout if a course is in the cart as we need a valid user to store data for |
|
| 390 | - add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) ); |
|
| 391 | - |
|
| 392 | - // Mark orders with virtual products as complete rather then stay processing |
|
| 393 | - add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 ); |
|
| 394 | - |
|
| 395 | - } // End set_woocommerce_functionality() |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Disable guest checkout if a course product is in the cart |
|
| 399 | - * @param boolean $guest_checkout Current guest checkout setting |
|
| 400 | - * @return boolean Modified guest checkout setting |
|
| 401 | - */ |
|
| 402 | - public function disable_guest_checkout( $guest_checkout ) { |
|
| 403 | - global $woocommerce; |
|
| 404 | - |
|
| 405 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 406 | - |
|
| 407 | - if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) { |
|
| 408 | - foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) { |
|
| 409 | - if( isset( $product['product_id'] ) ) { |
|
| 410 | - $args = array( |
|
| 411 | - 'posts_per_page' => -1, |
|
| 412 | - 'post_type' => 'course', |
|
| 413 | - 'meta_query' => array( |
|
| 414 | - array( |
|
| 415 | - 'key' => '_course_woocommerce_product', |
|
| 416 | - 'value' => $product['product_id'] |
|
| 417 | - ) |
|
| 418 | - ) |
|
| 419 | - ); |
|
| 420 | - $posts = get_posts( $args ); |
|
| 421 | - if( $posts && count( $posts ) > 0 ) { |
|
| 422 | - foreach( $posts as $course ) { |
|
| 423 | - $guest_checkout = ''; |
|
| 424 | - break; |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - return $guest_checkout; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Change order status with virtual products to completed |
|
| 437 | - * @since 1.1.0 |
|
| 438 | - * @param string $order_status |
|
| 439 | - * @param int $order_id |
|
| 440 | - * @return string |
|
| 441 | - **/ |
|
| 442 | - public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 443 | - $order = new WC_Order( $order_id ); |
|
| 444 | - if ( ! isset ( $order ) ) return; |
|
| 445 | - if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 446 | - $virtual_order = true; |
|
| 447 | - |
|
| 448 | - if ( count( $order->get_items() ) > 0 ) { |
|
| 449 | - foreach( $order->get_items() as $item ) { |
|
| 450 | - if ( $item['product_id'] > 0 ) { |
|
| 451 | - $_product = $order->get_product_from_item( $item ); |
|
| 452 | - if ( ! $_product->is_virtual() ) { |
|
| 453 | - $virtual_order = false; |
|
| 454 | - break; |
|
| 455 | - } // End If Statement |
|
| 456 | - } // End If Statement |
|
| 457 | - } // End For Loop |
|
| 458 | - } // End If Statement |
|
| 459 | - |
|
| 460 | - // virtual order, mark as completed |
|
| 461 | - if ( $virtual_order ) { |
|
| 462 | - return 'completed'; |
|
| 463 | - } // End If Statement |
|
| 464 | - } // End If Statement |
|
| 465 | - return $order_status; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * Register the widgets. |
|
| 470 | - * @access public |
|
| 471 | - * @since 1.0.0 |
|
| 472 | - * @return void |
|
| 473 | - */ |
|
| 474 | - public function register_widgets () { |
|
| 475 | - // Widget List (key => value is filename => widget class). |
|
| 476 | - $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
| 477 | - 'lesson-component' => 'Lesson_Component', |
|
| 478 | - 'course-categories' => 'Course_Categories', |
|
| 479 | - 'category-courses' => 'Category_Courses' ) |
|
| 480 | - ); |
|
| 481 | - foreach ( $widget_list as $key => $value ) { |
|
| 482 | - if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ) ) { |
|
| 483 | - require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ); |
|
| 484 | - register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
| 485 | - } |
|
| 486 | - } // End For Loop |
|
| 487 | - |
|
| 488 | - do_action( 'sensei_register_widgets' ); |
|
| 489 | - } // End register_widgets() |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * Load the plugin's localisation file. |
|
| 493 | - * @access public |
|
| 494 | - * @since 1.0.0 |
|
| 495 | - * @return void |
|
| 496 | - */ |
|
| 497 | - public function load_localisation () { |
|
| 498 | - load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 499 | - } // End load_localisation() |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * Load the plugin textdomain from the main WordPress "languages" folder. |
|
| 503 | - * @access public |
|
| 504 | - * @since 1.0.0 |
|
| 505 | - * @return void |
|
| 506 | - */ |
|
| 507 | - public function load_plugin_textdomain () { |
|
| 508 | - $domain = 'woothemes-sensei'; |
|
| 509 | - // The "plugin_locale" filter is also used in load_plugin_textdomain() |
|
| 510 | - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 511 | - load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
| 512 | - load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 513 | - } // End load_plugin_textdomain() |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Run on activation. |
|
| 517 | - * @access public |
|
| 518 | - * @since 1.0.0 |
|
| 519 | - * @return void |
|
| 520 | - */ |
|
| 521 | - public function activation () { |
|
| 522 | - $this->register_plugin_version(); |
|
| 523 | - } // End activation() |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Register activation hooks. |
|
| 528 | - * @access public |
|
| 529 | - * @since 1.0.0 |
|
| 530 | - * @return void |
|
| 531 | - */ |
|
| 532 | - public function install () { |
|
| 533 | - register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
| 534 | - register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
| 535 | - } // End install() |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * Run on activation of the plugin. |
|
| 540 | - * @access public |
|
| 541 | - * @since 1.0.0 |
|
| 542 | - * @return void |
|
| 543 | - */ |
|
| 544 | - public function activate_sensei () { |
|
| 545 | - update_option( 'skip_install_sensei_pages', 0 ); |
|
| 546 | - update_option( 'sensei_installed', 1 ); |
|
| 547 | - } // End activate_sensei() |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Register the plugin's version. |
|
| 551 | - * @access public |
|
| 552 | - * @since 1.0.0 |
|
| 553 | - * @return void |
|
| 554 | - */ |
|
| 555 | - private function register_plugin_version () { |
|
| 556 | - if ( $this->version != '' ) { |
|
| 557 | - |
|
| 558 | - // Check previous version to see if forced updates must run |
|
| 559 | - // $old_version = get_option( 'woothemes-sensei-version', false ); |
|
| 560 | - // if( $old_version && version_compare( $old_version, '1.7.0', '<' ) ) { |
|
| 561 | - // update_option( 'woothemes-sensei-force-updates', $this->version ); |
|
| 562 | - // } else { |
|
| 563 | - // delete_option( 'woothemes-sensei-force-updates' ); |
|
| 564 | - // } |
|
| 565 | - |
|
| 566 | - update_option( 'woothemes-sensei-version', $this->version ); |
|
| 567 | - } |
|
| 568 | - } // End register_plugin_version() |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Ensure that "post-thumbnails" support is available for those themes that don't register it. |
|
| 572 | - * @access public |
|
| 573 | - * @since 1.0.1 |
|
| 574 | - * @return void |
|
| 575 | - */ |
|
| 576 | - public function ensure_post_thumbnails_support () { |
|
| 577 | - if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
| 578 | - } // End ensure_post_thumbnails_support() |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * template_loader function. |
|
| 583 | - * |
|
| 584 | - * @access public |
|
| 585 | - * @param mixed $template |
|
| 586 | - * @return void |
|
| 587 | - * @deprecated |
|
| 588 | - */ |
|
| 589 | - public function template_loader ( $template = '' ) { |
|
| 590 | - |
|
| 591 | - _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
| 592 | - return Sensei_Templates::template_loader( $template ); |
|
| 593 | - |
|
| 594 | - } // End template_loader() |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * Determine the relative path to the plugin's directory. |
|
| 598 | - * @access public |
|
| 599 | - * @since 1.0.0 |
|
| 600 | - * @return string $sensei_plugin_path |
|
| 601 | - */ |
|
| 602 | - public function plugin_path () { |
|
| 603 | - |
|
| 604 | - if ( $this->plugin_path ) { |
|
| 605 | - |
|
| 606 | - $sensei_plugin_path = $this->plugin_path; |
|
| 607 | - |
|
| 608 | - }else{ |
|
| 609 | - |
|
| 610 | - $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
| 611 | - |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - return $sensei_plugin_path; |
|
| 615 | - |
|
| 616 | - } // End plugin_path() |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * Retrieve the ID of a specified page setting. |
|
| 621 | - * @access public |
|
| 622 | - * @since 1.0.0 |
|
| 623 | - * @param string $page |
|
| 624 | - * @return int |
|
| 625 | - */ |
|
| 626 | - public function get_page_id ( $page ) { |
|
| 627 | - $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
| 628 | - return ( $page ) ? $page : -1; |
|
| 629 | - } // End get_page_id() |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
| 634 | - * @access public |
|
| 635 | - * @since 1.0.0 |
|
| 636 | - * @param int $course_id (default: 0) |
|
| 637 | - * @param array/Object $order_user (default: array()) Specific user's data. |
|
| 638 | - * @return void |
|
| 639 | - */ |
|
| 640 | - public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
| 641 | - global $current_user; |
|
| 642 | - |
|
| 643 | - if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return; |
|
| 644 | - |
|
| 645 | - $data_update = false; |
|
| 646 | - |
|
| 647 | - // Get the product ID |
|
| 648 | - $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 649 | - |
|
| 650 | - // Check if in the admin |
|
| 651 | - if ( is_admin() ) { |
|
| 652 | - $user_login = $order_user['user_login']; |
|
| 653 | - $user_email = $order_user['user_email']; |
|
| 654 | - $user_url = $order_user['user_url']; |
|
| 655 | - $user_id = $order_user['ID']; |
|
| 656 | - } else { |
|
| 657 | - $user_login = $current_user->user_login; |
|
| 658 | - $user_email = $current_user->user_email; |
|
| 659 | - $user_url = $current_user->user_url; |
|
| 660 | - $user_id = $current_user->ID; |
|
| 661 | - } // End If Statement |
|
| 662 | - |
|
| 663 | - // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
|
| 664 | - $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 665 | - if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 666 | - $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 667 | - if ( ! $prereq_course_complete ) { |
|
| 668 | - // Remove all course user meta |
|
| 669 | - return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 674 | - |
|
| 675 | - if( ! $is_user_taking_course ) { |
|
| 676 | - |
|
| 677 | - if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
| 678 | - |
|
| 679 | - $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
| 680 | - |
|
| 681 | - $is_user_taking_course = false; |
|
| 682 | - if ( true == $activity_logged ) { |
|
| 683 | - $is_user_taking_course = true; |
|
| 684 | - } // End If Statement |
|
| 685 | - } // End If Statement |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - return $is_user_taking_course; |
|
| 689 | - } // End woocommerce_course_update() |
|
| 690 | - |
|
| 691 | - |
|
| 692 | - /** |
|
| 693 | - * check_user_permissions function. |
|
| 694 | - * |
|
| 695 | - * @access public |
|
| 696 | - * @param string $page (default: '') |
|
| 697 | - * @param array $data (default: array()) |
|
| 698 | - * @return bool |
|
| 699 | - */ |
|
| 700 | - public function check_user_permissions ( $page = '', $data = array() ) { |
|
| 701 | - // REFACTOR |
|
| 702 | - global $current_user, $post; |
|
| 703 | - |
|
| 704 | - // if use is not logged in |
|
| 705 | - if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') ){ |
|
| 706 | - $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
| 707 | - $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
| 708 | - return; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - // Get User Meta |
|
| 713 | - get_currentuserinfo(); |
|
| 714 | - |
|
| 715 | - $user_allowed = false; |
|
| 716 | - |
|
| 717 | - switch ( $page ) { |
|
| 718 | - case 'course-single': |
|
| 719 | - // check for prerequisite course or lesson, |
|
| 720 | - $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
| 721 | - $update_course = $this->woocommerce_course_update( $post->ID ); |
|
| 722 | - // Count completed lessons |
|
| 723 | - if ( 0 < absint( $course_prerequisite_id ) ) { |
|
| 724 | - |
|
| 725 | - $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
| 726 | - |
|
| 727 | - } |
|
| 728 | - else { |
|
| 729 | - $prerequisite_complete = true; |
|
| 730 | - } // End If Statement |
|
| 731 | - // Handles restrictions |
|
| 732 | - if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
| 733 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 734 | - $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 735 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
| 736 | - } else { |
|
| 737 | - $user_allowed = true; |
|
| 738 | - } // End If Statement |
|
| 739 | - break; |
|
| 740 | - case 'lesson-single': |
|
| 741 | - // Check for WC purchase |
|
| 742 | - $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
| 743 | - |
|
| 744 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 745 | - $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
| 746 | - if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 747 | - $user_allowed = true; |
|
| 748 | - } elseif( $this->access_settings() && false == $is_preview ) { |
|
| 749 | - |
|
| 750 | - $user_allowed = true; |
|
| 751 | - } else { |
|
| 752 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 753 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 754 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 755 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 756 | - if ( $is_preview ) { |
|
| 757 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 758 | - } else { |
|
| 759 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 760 | - } |
|
| 761 | - } else { |
|
| 762 | - if ( $is_preview ) { |
|
| 763 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 764 | - } else { |
|
| 765 | - /** This filter is documented in class-woothemes-sensei-frontend.php */ |
|
| 766 | - $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 767 | - } |
|
| 768 | - } // End If Statement |
|
| 769 | - } // End If Statement |
|
| 770 | - break; |
|
| 771 | - case 'quiz-single': |
|
| 772 | - $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
| 773 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
| 774 | - |
|
| 775 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 776 | - if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
| 777 | - |
|
| 778 | - // Check for prerequisite lesson for this quiz |
|
| 779 | - $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
| 780 | - $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
| 781 | - |
|
| 782 | - // Handle restrictions |
|
| 783 | - if( sensei_all_access() ) { |
|
| 784 | - $user_allowed = true; |
|
| 785 | - } else { |
|
| 786 | - if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
| 787 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 788 | - $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 789 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
| 790 | - } else { |
|
| 791 | - $user_allowed = true; |
|
| 792 | - } // End If Statement |
|
| 793 | - } // End If Statement |
|
| 794 | - } elseif( $this->access_settings() ) { |
|
| 795 | - // Check if the user has started the course |
|
| 796 | - |
|
| 797 | - if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) { |
|
| 798 | - |
|
| 799 | - $user_allowed = false; |
|
| 800 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 801 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 802 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 803 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 804 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 805 | - } else { |
|
| 806 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 807 | - } // End If Statement |
|
| 808 | - } else { |
|
| 809 | - $user_allowed = true; |
|
| 810 | - } // End If Statement |
|
| 811 | - } else { |
|
| 812 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 813 | - $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 814 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 815 | - } // End If Statement |
|
| 816 | - break; |
|
| 817 | - default: |
|
| 818 | - $user_allowed = true; |
|
| 819 | - break; |
|
| 820 | - |
|
| 821 | - } // End Switch Statement |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * filter the permissions message shown on sensei post types. |
|
| 825 | - * |
|
| 826 | - * @since 1.8.7 |
|
| 827 | - * |
|
| 828 | - * @param array $permissions_message{ |
|
| 829 | - * |
|
| 830 | - * @type string $title |
|
| 831 | - * @type string $message |
|
| 832 | - * |
|
| 833 | - * } |
|
| 834 | - * @param string $post_id |
|
| 835 | - */ |
|
| 836 | - $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
| 840 | - $user_allowed = true; |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - return apply_filters( 'sensei_access_permissions', $user_allowed ); |
|
| 844 | - } // End get_placeholder_image() |
|
| 845 | - |
|
| 846 | - |
|
| 847 | - /** |
|
| 848 | - * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
|
| 849 | - * @since 1.0.0 |
|
| 850 | - * @access public |
|
| 851 | - * @return void |
|
| 852 | - */ |
|
| 853 | - public function access_settings () { |
|
| 854 | - |
|
| 855 | - if( sensei_all_access() ) return true; |
|
| 856 | - |
|
| 857 | - if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
| 858 | - if ( is_user_logged_in() ) { |
|
| 859 | - return true; |
|
| 860 | - } else { |
|
| 861 | - return false; |
|
| 862 | - } // End If Statement |
|
| 863 | - } else { |
|
| 864 | - return true; |
|
| 865 | - } // End If Statement |
|
| 866 | - } // End access_settings() |
|
| 867 | - |
|
| 868 | - /** |
|
| 869 | - * sensei_woocommerce_complete_order description |
|
| 870 | - * @since 1.0.3 |
|
| 871 | - * @access public |
|
| 872 | - * @param int $order_id WC order ID |
|
| 873 | - * @return void |
|
| 874 | - */ |
|
| 875 | - public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
| 876 | - $order_user = array(); |
|
| 877 | - // Check for WooCommerce |
|
| 878 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 879 | - // Get order object |
|
| 880 | - $order = new WC_Order( $order_id ); |
|
| 881 | - $user = get_user_by( 'id', $order->user_id ); |
|
| 882 | - $order_user['ID'] = $user->ID; |
|
| 883 | - $order_user['user_login'] = $user->user_login; |
|
| 884 | - $order_user['user_email'] = $user->user_email; |
|
| 885 | - $order_user['user_url'] = $user->user_url; |
|
| 886 | - // Run through each product ordered |
|
| 887 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 888 | - foreach( $order->get_items() as $item ) { |
|
| 889 | - $product_type = ''; |
|
| 890 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 891 | - $item_id = $item['variation_id']; |
|
| 892 | - $product_type = 'variation'; |
|
| 893 | - } else { |
|
| 894 | - $item_id = $item['product_id']; |
|
| 895 | - } // End If Statement |
|
| 896 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 897 | - // Get courses that use the WC product |
|
| 898 | - $courses = $this->post_types->course->get_product_courses( $_product->id ); |
|
| 899 | - // Loop and update those courses |
|
| 900 | - foreach ( $courses as $course_item ) { |
|
| 901 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 902 | - } // End For Loop |
|
| 903 | - } // End For Loop |
|
| 904 | - } // End If Statement |
|
| 905 | - // Add meta to indicate that payment has been completed successfully |
|
| 906 | - update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 907 | - } // End If Statement |
|
| 908 | - } // End sensei_woocommerce_complete_order() |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * Runs when an order is cancelled. |
|
| 912 | - * @since 1.2.0 |
|
| 913 | - * @access public |
|
| 914 | - * @param integer $order_id order ID |
|
| 915 | - * @return void |
|
| 916 | - */ |
|
| 917 | - public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
| 918 | - |
|
| 919 | - // Get order object |
|
| 920 | - $order = new WC_Order( $order_id ); |
|
| 921 | - |
|
| 922 | - // Run through each product ordered |
|
| 923 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 924 | - |
|
| 925 | - // Get order user |
|
| 926 | - $user_id = $order->__get( 'user_id' ); |
|
| 927 | - |
|
| 928 | - foreach( $order->get_items() as $item ) { |
|
| 929 | - |
|
| 930 | - $product_type = ''; |
|
| 931 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 932 | - $item_id = $item['variation_id']; |
|
| 933 | - $product_type = 'variation'; |
|
| 934 | - } else { |
|
| 935 | - $item_id = $item['product_id']; |
|
| 936 | - } // End If Statement |
|
| 937 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 938 | - |
|
| 939 | - // Get courses that use the WC product |
|
| 940 | - $courses = array(); |
|
| 941 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 942 | - |
|
| 943 | - // Loop and update those courses |
|
| 944 | - foreach ($courses as $course_item){ |
|
| 945 | - // Check and Remove course from courses user meta |
|
| 946 | - $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 947 | - } // End For Loop |
|
| 948 | - } // End For Loop |
|
| 949 | - } // End If Statement |
|
| 950 | - } // End sensei_woocommerce_cancel_order() |
|
| 951 | - |
|
| 952 | - /** |
|
| 953 | - * Runs when an subscription is cancelled or expires. |
|
| 954 | - * @since 1.3.3 |
|
| 955 | - * @access public |
|
| 956 | - * @param integer $user_id User ID |
|
| 957 | - * @param integer $subscription_key Subscription Unique Key |
|
| 958 | - * @return void |
|
| 959 | - */ |
|
| 960 | - public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) { |
|
| 961 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 962 | - self::sensei_woocommerce_cancel_order( $subscription['order_id'] ); |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - /** |
|
| 966 | - * Runs when an subscription is re-activated after suspension. |
|
| 967 | - * @since 1.3.3 |
|
| 968 | - * @access public |
|
| 969 | - * @param integer $user_id User ID |
|
| 970 | - * @param integer $subscription_key Subscription Unique Key |
|
| 971 | - * @return void |
|
| 972 | - */ |
|
| 973 | - public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) { |
|
| 974 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 975 | - $order = new WC_Order( $subscription['order_id'] ); |
|
| 976 | - $user = get_user_by( 'id', $order->user_id ); |
|
| 977 | - $order_user = array(); |
|
| 978 | - $order_user['ID'] = $user->ID; |
|
| 979 | - $order_user['user_login'] = $user->user_login; |
|
| 980 | - $order_user['user_email'] = $user->user_email; |
|
| 981 | - $order_user['user_url'] = $user->user_url; |
|
| 982 | - $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] ); |
|
| 983 | - foreach ( $courses as $course_item ){ |
|
| 984 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 985 | - } // End For Loop |
|
| 986 | - } // End sensei_woocommerce_reactivate_subscription |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * Returns the WooCommerce Product Object |
|
| 990 | - * |
|
| 991 | - * The code caters for pre and post WooCommerce 2.2 installations. |
|
| 992 | - * |
|
| 993 | - * @since 1.1.1 |
|
| 994 | - * @access public |
|
| 995 | - * @param integer $wc_product_id Product ID or Variation ID |
|
| 996 | - * @param string $product_type '' or 'variation' |
|
| 997 | - * @return WC_Product $wc_product_object |
|
| 998 | - */ |
|
| 999 | - public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1000 | - |
|
| 1001 | - $wc_product_object = false; |
|
| 1002 | - if ( 0 < intval( $wc_product_id ) ) { |
|
| 1003 | - |
|
| 1004 | - // Get the product |
|
| 1005 | - if ( function_exists( 'wc_get_product' ) ) { |
|
| 1006 | - |
|
| 1007 | - $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1008 | - |
|
| 1009 | - } elseif ( function_exists( 'get_product' ) ) { |
|
| 1010 | - |
|
| 1011 | - $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1012 | - |
|
| 1013 | - } else { |
|
| 1014 | - |
|
| 1015 | - // Pre WC 2.0 |
|
| 1016 | - if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1017 | - |
|
| 1018 | - $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1019 | - |
|
| 1020 | - } else { |
|
| 1021 | - |
|
| 1022 | - $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1023 | - |
|
| 1024 | - } // End If Statement |
|
| 1025 | - |
|
| 1026 | - } // End If Statement |
|
| 1027 | - |
|
| 1028 | - } // End If Statement |
|
| 1029 | - |
|
| 1030 | - return $wc_product_object; |
|
| 1031 | - |
|
| 1032 | - } // End sensei_get_woocommerce_product_object() |
|
| 1033 | - |
|
| 1034 | - /** |
|
| 1035 | - * load_class loads in class files |
|
| 1036 | - * @since 1.2.0 |
|
| 1037 | - * @access public |
|
| 1038 | - * @return void |
|
| 1039 | - */ |
|
| 1040 | - public function load_class ( $class_name = '' ) { |
|
| 1041 | - if ( '' != $class_name && '' != $this->token ) { |
|
| 1042 | - require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
| 1043 | - } // End If Statement |
|
| 1044 | - } // End load_class() |
|
| 1045 | - |
|
| 1046 | - /** |
|
| 1047 | - * sensei_activate_subscription runs when a subscription product is purchased |
|
| 1048 | - * @since 1.2.0 |
|
| 1049 | - * @access public |
|
| 1050 | - * @param integer $order_id order ID |
|
| 1051 | - * @return void |
|
| 1052 | - */ |
|
| 1053 | - public function sensei_activate_subscription( $order_id = 0 ) { |
|
| 1054 | - if ( 0 < intval( $order_id ) ) { |
|
| 1055 | - $order = new WC_Order( $order_id ); |
|
| 1056 | - $user = get_user_by('id', $order->user_id); |
|
| 1057 | - $order_user['ID'] = $user->ID; |
|
| 1058 | - $order_user['user_login'] = $user->user_login; |
|
| 1059 | - $order_user['user_email'] = $user->user_email; |
|
| 1060 | - $order_user['user_url'] = $user->user_url; |
|
| 1061 | - // Run through each product ordered |
|
| 1062 | - if (sizeof($order->get_items())>0) { |
|
| 1063 | - foreach($order->get_items() as $item) { |
|
| 1064 | - $product_type = ''; |
|
| 1065 | - if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
| 1066 | - $item_id = $item['variation_id']; |
|
| 1067 | - $product_type = 'subscription_variation'; |
|
| 1068 | - } else { |
|
| 1069 | - $item_id = $item['product_id']; |
|
| 1070 | - } // End If Statement |
|
| 1071 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 1072 | - // Get courses that use the WC product |
|
| 1073 | - $courses = array(); |
|
| 1074 | - if ( $product_type == 'subscription_variation' ) { |
|
| 1075 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 1076 | - } // End If Statement |
|
| 1077 | - // Loop and update those courses |
|
| 1078 | - foreach ($courses as $course_item){ |
|
| 1079 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 1080 | - } // End For Loop |
|
| 1081 | - } // End For Loop |
|
| 1082 | - } // End If Statement |
|
| 1083 | - } // End If Statement |
|
| 1084 | - } // End sensei_activate_subscription() |
|
| 1085 | - |
|
| 1086 | - /** |
|
| 1087 | - * sensei_woocommerce_email_course_details adds detail to email |
|
| 1088 | - * @since 1.4.5 |
|
| 1089 | - * @access public |
|
| 1090 | - * @param WC_Order $order |
|
| 1091 | - * @return void |
|
| 1092 | - */ |
|
| 1093 | - public function sensei_woocommerce_email_course_details( $order ) { |
|
| 1094 | - global $woocommerce; |
|
| 1095 | - |
|
| 1096 | - // exit early if not wc-completed or wc-processing |
|
| 1097 | - if( 'wc-completed' != $order->post_status |
|
| 1098 | - && 'wc-processing' != $order->post_status ) { |
|
| 1099 | - return; |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - $order_items = $order->get_items(); |
|
| 1103 | - $order_id = $order->id; |
|
| 1104 | - |
|
| 1105 | - //If object have items go through them all to find course |
|
| 1106 | - if ( 0 < sizeof( $order_items ) ) { |
|
| 1107 | - |
|
| 1108 | - echo '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1109 | - |
|
| 1110 | - foreach ( $order_items as $item ) { |
|
| 1111 | - |
|
| 1112 | - $product_type = ''; |
|
| 1113 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1114 | - // If item has variation_id then its from variation |
|
| 1115 | - $item_id = $item['variation_id']; |
|
| 1116 | - $product_type = 'variation'; |
|
| 1117 | - } else { |
|
| 1118 | - // If not its real product set its id to item_id |
|
| 1119 | - $item_id = $item['product_id']; |
|
| 1120 | - } // End If Statement |
|
| 1121 | - |
|
| 1122 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1123 | - |
|
| 1124 | - if( $user_id ) { |
|
| 1125 | - |
|
| 1126 | - // Get all courses for product |
|
| 1127 | - $args = array( |
|
| 1128 | - 'posts_per_page' => -1, |
|
| 1129 | - 'post_type' => 'course', |
|
| 1130 | - 'meta_query' => array( |
|
| 1131 | - array( |
|
| 1132 | - 'key' => '_course_woocommerce_product', |
|
| 1133 | - 'value' => $item_id |
|
| 1134 | - ) |
|
| 1135 | - ), |
|
| 1136 | - 'orderby' => 'menu_order date', |
|
| 1137 | - 'order' => 'ASC', |
|
| 1138 | - ); |
|
| 1139 | - $courses = get_posts( $args ); |
|
| 1140 | - |
|
| 1141 | - if( $courses && count( $courses ) > 0 ) { |
|
| 1142 | - |
|
| 1143 | - foreach( $courses as $course ) { |
|
| 1144 | - |
|
| 1145 | - $title = $course->post_title; |
|
| 1146 | - $permalink = get_permalink( $course->ID ); |
|
| 1147 | - |
|
| 1148 | - echo '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1149 | - } |
|
| 1150 | - } |
|
| 1151 | - } |
|
| 1152 | - } |
|
| 1153 | - } |
|
| 1154 | - } |
|
| 1155 | - |
|
| 1156 | - /** |
|
| 1157 | - * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
| 1158 | - * @since 1.4.0 |
|
| 1159 | - * @access public |
|
| 1160 | - * @param array $comments |
|
| 1161 | - * @param integer $post_id |
|
| 1162 | - * @return array |
|
| 1163 | - */ |
|
| 1164 | - public function sensei_count_comments( $comments, $post_id ) { |
|
| 1165 | - global $wpdb; |
|
| 1166 | - |
|
| 1167 | - $post_id = (int) $post_id; |
|
| 1168 | - |
|
| 1169 | - $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
| 1170 | - |
|
| 1171 | - if ( false !== $count ) { |
|
| 1172 | - return $count; |
|
| 1173 | - } |
|
| 1174 | - |
|
| 1175 | - $statuses = array( '' ); // Default to the WP normal comments |
|
| 1176 | - $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
| 1177 | - foreach ( (array) $stati AS $status ) { |
|
| 1178 | - if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
| 1179 | - $statuses[] = $status['comment_type']; |
|
| 1180 | - } |
|
| 1181 | - } |
|
| 1182 | - $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
| 1183 | - |
|
| 1184 | - if ( $post_id > 0 ) |
|
| 1185 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1186 | - |
|
| 1187 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 1188 | - |
|
| 1189 | - $total = 0; |
|
| 1190 | - $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
| 1191 | - foreach ( (array) $count as $row ) { |
|
| 1192 | - // Don't count post-trashed toward totals |
|
| 1193 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 1194 | - $total += $row['num_comments']; |
|
| 1195 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 1196 | - $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - $stats['total_comments'] = $total; |
|
| 1200 | - foreach ( $approved as $key ) { |
|
| 1201 | - if ( empty($stats[$key]) ) |
|
| 1202 | - $stats[$key] = 0; |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - $stats = (object) $stats; |
|
| 1206 | - wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
| 1207 | - |
|
| 1208 | - return $stats; |
|
| 1209 | - } |
|
| 1210 | - |
|
| 1211 | - /** |
|
| 1212 | - * Init images. |
|
| 1213 | - * |
|
| 1214 | - * @since 1.4.5 |
|
| 1215 | - * @access public |
|
| 1216 | - * @return void |
|
| 1217 | - */ |
|
| 1218 | - public function init_image_sizes() { |
|
| 1219 | - $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
| 1220 | - $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
| 1221 | - $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
| 1222 | - $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
| 1223 | - |
|
| 1224 | - add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
| 1225 | - add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
| 1226 | - add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
| 1227 | - add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - /** |
|
| 1231 | - * Get an image size. |
|
| 1232 | - * |
|
| 1233 | - * Variable is filtered by sensei_get_image_size_{image_size} |
|
| 1234 | - * |
|
| 1235 | - * @since 1.4.5 |
|
| 1236 | - * @access public |
|
| 1237 | - * @param mixed $image_size |
|
| 1238 | - * @return string |
|
| 1239 | - */ |
|
| 1240 | - public function get_image_size( $image_size ) { |
|
| 1241 | - |
|
| 1242 | - // Only return sizes we define in settings |
|
| 1243 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 1244 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1245 | - |
|
| 1246 | - if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
| 1247 | - $this->settings->settings[ $image_size . '_width' ] = false; |
|
| 1248 | - } |
|
| 1249 | - if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
| 1250 | - $this->settings->settings[ $image_size . '_height' ] = false; |
|
| 1251 | - } |
|
| 1252 | - if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
| 1253 | - $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - $size = array_filter( array( |
|
| 1257 | - 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
| 1258 | - 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
| 1259 | - 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
| 1260 | - ) ); |
|
| 1261 | - |
|
| 1262 | - $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
| 1263 | - $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
| 1264 | - $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
| 1265 | - |
|
| 1266 | - return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - public function body_class( $classes ) { |
|
| 1270 | - if( is_sensei() ) { |
|
| 1271 | - $classes[] = 'sensei'; |
|
| 1272 | - } |
|
| 1273 | - return $classes; |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - /** |
|
| 1277 | - * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
| 1278 | - * |
|
| 1279 | - * @return null |
|
| 1280 | - * @since 1.7.0 |
|
| 1281 | - */ |
|
| 1282 | - public function jetpack_latex_support() { |
|
| 1283 | - if ( function_exists( 'latex_markup') ) { |
|
| 1284 | - add_filter( 'sensei_question_title', 'latex_markup' ); |
|
| 1285 | - add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
| 1286 | - } |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - /** |
|
| 1290 | - * Load the module functionality. |
|
| 1291 | - * |
|
| 1292 | - * This function is hooked into plugins_loaded to avoid conflicts with |
|
| 1293 | - * the retired modules extension. |
|
| 1294 | - * |
|
| 1295 | - * @since 1.8.0 |
|
| 1296 | - */ |
|
| 1297 | - public function load_modules_class(){ |
|
| 1298 | - global $sensei_modules; |
|
| 1299 | - |
|
| 1300 | - if( !class_exists( 'Sensei_Modules' ) |
|
| 1301 | - && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
| 1302 | - |
|
| 1303 | - //Load the modules class |
|
| 1304 | - require_once( 'class-sensei-modules.php'); |
|
| 1305 | - Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
| 1306 | - |
|
| 1307 | - }else{ |
|
| 1308 | - // fallback for people still using the modules extension. |
|
| 1309 | - global $sensei_modules; |
|
| 1310 | - Sensei()->modules = $sensei_modules; |
|
| 1311 | - add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
| 1312 | - } |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - /** |
|
| 1316 | - * Tell the user to that the modules extension is no longer needed. |
|
| 1317 | - * |
|
| 1318 | - * @since 1.8.0 |
|
| 1319 | - */ |
|
| 1320 | - public function disable_sensei_modules_extension(){ ?> |
|
| 308 | + /** |
|
| 309 | + * This function is linked into the activation |
|
| 310 | + * hook to reset flush the urls to ensure Sensei post types show up. |
|
| 311 | + * |
|
| 312 | + * @since 1.9.0 |
|
| 313 | + * |
|
| 314 | + * @param $plugin |
|
| 315 | + */ |
|
| 316 | + public static function activation_flush_rules( $plugin ){ |
|
| 317 | + |
|
| 318 | + if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
| 319 | + |
|
| 320 | + flush_rewrite_rules(true); |
|
| 321 | + |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Global Sensei Instance |
|
| 328 | + * |
|
| 329 | + * Ensure that only one instance of the main Sensei class can be loaded. |
|
| 330 | + * |
|
| 331 | + * @since 1.8.0 |
|
| 332 | + * @static |
|
| 333 | + * @see WC() |
|
| 334 | + * @return WooThemes_Sensei Instance. |
|
| 335 | + */ |
|
| 336 | + public static function instance() { |
|
| 337 | + |
|
| 338 | + if ( is_null( self::$_instance ) ) { |
|
| 339 | + |
|
| 340 | + //Sensei requires a reference to the main Sensei plugin file |
|
| 341 | + $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
| 342 | + |
|
| 343 | + self::$_instance = new self( $sensei_main_plugin_file ); |
|
| 344 | + |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + return self::$_instance; |
|
| 348 | + |
|
| 349 | + } // end instance() |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * Cloning is forbidden. |
|
| 353 | + * @since 1.8.0 |
|
| 354 | + */ |
|
| 355 | + public function __clone() { |
|
| 356 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Unserializing instances of this class is forbidden. |
|
| 361 | + * @since 1.8.0 |
|
| 362 | + */ |
|
| 363 | + public function __wakeup() { |
|
| 364 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * Run Sensei updates. |
|
| 369 | + * @access public |
|
| 370 | + * @since 1.1.0 |
|
| 371 | + * @return void |
|
| 372 | + */ |
|
| 373 | + public function run_updates() { |
|
| 374 | + // Run updates if administrator |
|
| 375 | + if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
| 376 | + |
|
| 377 | + $this->updates->update(); |
|
| 378 | + |
|
| 379 | + } // End If Statement |
|
| 380 | + } // End run_updates() |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Setup required WooCommerce settings. |
|
| 384 | + * @access public |
|
| 385 | + * @since 1.1.0 |
|
| 386 | + * @return void |
|
| 387 | + */ |
|
| 388 | + public function set_woocommerce_functionality() { |
|
| 389 | + // Disable guest checkout if a course is in the cart as we need a valid user to store data for |
|
| 390 | + add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) ); |
|
| 391 | + |
|
| 392 | + // Mark orders with virtual products as complete rather then stay processing |
|
| 393 | + add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 ); |
|
| 394 | + |
|
| 395 | + } // End set_woocommerce_functionality() |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Disable guest checkout if a course product is in the cart |
|
| 399 | + * @param boolean $guest_checkout Current guest checkout setting |
|
| 400 | + * @return boolean Modified guest checkout setting |
|
| 401 | + */ |
|
| 402 | + public function disable_guest_checkout( $guest_checkout ) { |
|
| 403 | + global $woocommerce; |
|
| 404 | + |
|
| 405 | + if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 406 | + |
|
| 407 | + if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) { |
|
| 408 | + foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) { |
|
| 409 | + if( isset( $product['product_id'] ) ) { |
|
| 410 | + $args = array( |
|
| 411 | + 'posts_per_page' => -1, |
|
| 412 | + 'post_type' => 'course', |
|
| 413 | + 'meta_query' => array( |
|
| 414 | + array( |
|
| 415 | + 'key' => '_course_woocommerce_product', |
|
| 416 | + 'value' => $product['product_id'] |
|
| 417 | + ) |
|
| 418 | + ) |
|
| 419 | + ); |
|
| 420 | + $posts = get_posts( $args ); |
|
| 421 | + if( $posts && count( $posts ) > 0 ) { |
|
| 422 | + foreach( $posts as $course ) { |
|
| 423 | + $guest_checkout = ''; |
|
| 424 | + break; |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + return $guest_checkout; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Change order status with virtual products to completed |
|
| 437 | + * @since 1.1.0 |
|
| 438 | + * @param string $order_status |
|
| 439 | + * @param int $order_id |
|
| 440 | + * @return string |
|
| 441 | + **/ |
|
| 442 | + public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 443 | + $order = new WC_Order( $order_id ); |
|
| 444 | + if ( ! isset ( $order ) ) return; |
|
| 445 | + if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 446 | + $virtual_order = true; |
|
| 447 | + |
|
| 448 | + if ( count( $order->get_items() ) > 0 ) { |
|
| 449 | + foreach( $order->get_items() as $item ) { |
|
| 450 | + if ( $item['product_id'] > 0 ) { |
|
| 451 | + $_product = $order->get_product_from_item( $item ); |
|
| 452 | + if ( ! $_product->is_virtual() ) { |
|
| 453 | + $virtual_order = false; |
|
| 454 | + break; |
|
| 455 | + } // End If Statement |
|
| 456 | + } // End If Statement |
|
| 457 | + } // End For Loop |
|
| 458 | + } // End If Statement |
|
| 459 | + |
|
| 460 | + // virtual order, mark as completed |
|
| 461 | + if ( $virtual_order ) { |
|
| 462 | + return 'completed'; |
|
| 463 | + } // End If Statement |
|
| 464 | + } // End If Statement |
|
| 465 | + return $order_status; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * Register the widgets. |
|
| 470 | + * @access public |
|
| 471 | + * @since 1.0.0 |
|
| 472 | + * @return void |
|
| 473 | + */ |
|
| 474 | + public function register_widgets () { |
|
| 475 | + // Widget List (key => value is filename => widget class). |
|
| 476 | + $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
| 477 | + 'lesson-component' => 'Lesson_Component', |
|
| 478 | + 'course-categories' => 'Course_Categories', |
|
| 479 | + 'category-courses' => 'Category_Courses' ) |
|
| 480 | + ); |
|
| 481 | + foreach ( $widget_list as $key => $value ) { |
|
| 482 | + if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ) ) { |
|
| 483 | + require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ); |
|
| 484 | + register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
| 485 | + } |
|
| 486 | + } // End For Loop |
|
| 487 | + |
|
| 488 | + do_action( 'sensei_register_widgets' ); |
|
| 489 | + } // End register_widgets() |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * Load the plugin's localisation file. |
|
| 493 | + * @access public |
|
| 494 | + * @since 1.0.0 |
|
| 495 | + * @return void |
|
| 496 | + */ |
|
| 497 | + public function load_localisation () { |
|
| 498 | + load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 499 | + } // End load_localisation() |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * Load the plugin textdomain from the main WordPress "languages" folder. |
|
| 503 | + * @access public |
|
| 504 | + * @since 1.0.0 |
|
| 505 | + * @return void |
|
| 506 | + */ |
|
| 507 | + public function load_plugin_textdomain () { |
|
| 508 | + $domain = 'woothemes-sensei'; |
|
| 509 | + // The "plugin_locale" filter is also used in load_plugin_textdomain() |
|
| 510 | + $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 511 | + load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
| 512 | + load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 513 | + } // End load_plugin_textdomain() |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Run on activation. |
|
| 517 | + * @access public |
|
| 518 | + * @since 1.0.0 |
|
| 519 | + * @return void |
|
| 520 | + */ |
|
| 521 | + public function activation () { |
|
| 522 | + $this->register_plugin_version(); |
|
| 523 | + } // End activation() |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Register activation hooks. |
|
| 528 | + * @access public |
|
| 529 | + * @since 1.0.0 |
|
| 530 | + * @return void |
|
| 531 | + */ |
|
| 532 | + public function install () { |
|
| 533 | + register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
| 534 | + register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
| 535 | + } // End install() |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * Run on activation of the plugin. |
|
| 540 | + * @access public |
|
| 541 | + * @since 1.0.0 |
|
| 542 | + * @return void |
|
| 543 | + */ |
|
| 544 | + public function activate_sensei () { |
|
| 545 | + update_option( 'skip_install_sensei_pages', 0 ); |
|
| 546 | + update_option( 'sensei_installed', 1 ); |
|
| 547 | + } // End activate_sensei() |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Register the plugin's version. |
|
| 551 | + * @access public |
|
| 552 | + * @since 1.0.0 |
|
| 553 | + * @return void |
|
| 554 | + */ |
|
| 555 | + private function register_plugin_version () { |
|
| 556 | + if ( $this->version != '' ) { |
|
| 557 | + |
|
| 558 | + // Check previous version to see if forced updates must run |
|
| 559 | + // $old_version = get_option( 'woothemes-sensei-version', false ); |
|
| 560 | + // if( $old_version && version_compare( $old_version, '1.7.0', '<' ) ) { |
|
| 561 | + // update_option( 'woothemes-sensei-force-updates', $this->version ); |
|
| 562 | + // } else { |
|
| 563 | + // delete_option( 'woothemes-sensei-force-updates' ); |
|
| 564 | + // } |
|
| 565 | + |
|
| 566 | + update_option( 'woothemes-sensei-version', $this->version ); |
|
| 567 | + } |
|
| 568 | + } // End register_plugin_version() |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Ensure that "post-thumbnails" support is available for those themes that don't register it. |
|
| 572 | + * @access public |
|
| 573 | + * @since 1.0.1 |
|
| 574 | + * @return void |
|
| 575 | + */ |
|
| 576 | + public function ensure_post_thumbnails_support () { |
|
| 577 | + if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
| 578 | + } // End ensure_post_thumbnails_support() |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * template_loader function. |
|
| 583 | + * |
|
| 584 | + * @access public |
|
| 585 | + * @param mixed $template |
|
| 586 | + * @return void |
|
| 587 | + * @deprecated |
|
| 588 | + */ |
|
| 589 | + public function template_loader ( $template = '' ) { |
|
| 590 | + |
|
| 591 | + _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
| 592 | + return Sensei_Templates::template_loader( $template ); |
|
| 593 | + |
|
| 594 | + } // End template_loader() |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * Determine the relative path to the plugin's directory. |
|
| 598 | + * @access public |
|
| 599 | + * @since 1.0.0 |
|
| 600 | + * @return string $sensei_plugin_path |
|
| 601 | + */ |
|
| 602 | + public function plugin_path () { |
|
| 603 | + |
|
| 604 | + if ( $this->plugin_path ) { |
|
| 605 | + |
|
| 606 | + $sensei_plugin_path = $this->plugin_path; |
|
| 607 | + |
|
| 608 | + }else{ |
|
| 609 | + |
|
| 610 | + $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
| 611 | + |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + return $sensei_plugin_path; |
|
| 615 | + |
|
| 616 | + } // End plugin_path() |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Retrieve the ID of a specified page setting. |
|
| 621 | + * @access public |
|
| 622 | + * @since 1.0.0 |
|
| 623 | + * @param string $page |
|
| 624 | + * @return int |
|
| 625 | + */ |
|
| 626 | + public function get_page_id ( $page ) { |
|
| 627 | + $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
| 628 | + return ( $page ) ? $page : -1; |
|
| 629 | + } // End get_page_id() |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
| 634 | + * @access public |
|
| 635 | + * @since 1.0.0 |
|
| 636 | + * @param int $course_id (default: 0) |
|
| 637 | + * @param array/Object $order_user (default: array()) Specific user's data. |
|
| 638 | + * @return void |
|
| 639 | + */ |
|
| 640 | + public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
| 641 | + global $current_user; |
|
| 642 | + |
|
| 643 | + if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return; |
|
| 644 | + |
|
| 645 | + $data_update = false; |
|
| 646 | + |
|
| 647 | + // Get the product ID |
|
| 648 | + $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 649 | + |
|
| 650 | + // Check if in the admin |
|
| 651 | + if ( is_admin() ) { |
|
| 652 | + $user_login = $order_user['user_login']; |
|
| 653 | + $user_email = $order_user['user_email']; |
|
| 654 | + $user_url = $order_user['user_url']; |
|
| 655 | + $user_id = $order_user['ID']; |
|
| 656 | + } else { |
|
| 657 | + $user_login = $current_user->user_login; |
|
| 658 | + $user_email = $current_user->user_email; |
|
| 659 | + $user_url = $current_user->user_url; |
|
| 660 | + $user_id = $current_user->ID; |
|
| 661 | + } // End If Statement |
|
| 662 | + |
|
| 663 | + // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
|
| 664 | + $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 665 | + if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 666 | + $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 667 | + if ( ! $prereq_course_complete ) { |
|
| 668 | + // Remove all course user meta |
|
| 669 | + return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 674 | + |
|
| 675 | + if( ! $is_user_taking_course ) { |
|
| 676 | + |
|
| 677 | + if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
| 678 | + |
|
| 679 | + $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
| 680 | + |
|
| 681 | + $is_user_taking_course = false; |
|
| 682 | + if ( true == $activity_logged ) { |
|
| 683 | + $is_user_taking_course = true; |
|
| 684 | + } // End If Statement |
|
| 685 | + } // End If Statement |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + return $is_user_taking_course; |
|
| 689 | + } // End woocommerce_course_update() |
|
| 690 | + |
|
| 691 | + |
|
| 692 | + /** |
|
| 693 | + * check_user_permissions function. |
|
| 694 | + * |
|
| 695 | + * @access public |
|
| 696 | + * @param string $page (default: '') |
|
| 697 | + * @param array $data (default: array()) |
|
| 698 | + * @return bool |
|
| 699 | + */ |
|
| 700 | + public function check_user_permissions ( $page = '', $data = array() ) { |
|
| 701 | + // REFACTOR |
|
| 702 | + global $current_user, $post; |
|
| 703 | + |
|
| 704 | + // if use is not logged in |
|
| 705 | + if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') ){ |
|
| 706 | + $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
| 707 | + $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
| 708 | + return; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + // Get User Meta |
|
| 713 | + get_currentuserinfo(); |
|
| 714 | + |
|
| 715 | + $user_allowed = false; |
|
| 716 | + |
|
| 717 | + switch ( $page ) { |
|
| 718 | + case 'course-single': |
|
| 719 | + // check for prerequisite course or lesson, |
|
| 720 | + $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
| 721 | + $update_course = $this->woocommerce_course_update( $post->ID ); |
|
| 722 | + // Count completed lessons |
|
| 723 | + if ( 0 < absint( $course_prerequisite_id ) ) { |
|
| 724 | + |
|
| 725 | + $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
| 726 | + |
|
| 727 | + } |
|
| 728 | + else { |
|
| 729 | + $prerequisite_complete = true; |
|
| 730 | + } // End If Statement |
|
| 731 | + // Handles restrictions |
|
| 732 | + if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
| 733 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 734 | + $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 735 | + $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
| 736 | + } else { |
|
| 737 | + $user_allowed = true; |
|
| 738 | + } // End If Statement |
|
| 739 | + break; |
|
| 740 | + case 'lesson-single': |
|
| 741 | + // Check for WC purchase |
|
| 742 | + $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
| 743 | + |
|
| 744 | + $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 745 | + $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
| 746 | + if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 747 | + $user_allowed = true; |
|
| 748 | + } elseif( $this->access_settings() && false == $is_preview ) { |
|
| 749 | + |
|
| 750 | + $user_allowed = true; |
|
| 751 | + } else { |
|
| 752 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 753 | + $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 754 | + $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 755 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 756 | + if ( $is_preview ) { |
|
| 757 | + $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 758 | + } else { |
|
| 759 | + $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 760 | + } |
|
| 761 | + } else { |
|
| 762 | + if ( $is_preview ) { |
|
| 763 | + $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 764 | + } else { |
|
| 765 | + /** This filter is documented in class-woothemes-sensei-frontend.php */ |
|
| 766 | + $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 767 | + } |
|
| 768 | + } // End If Statement |
|
| 769 | + } // End If Statement |
|
| 770 | + break; |
|
| 771 | + case 'quiz-single': |
|
| 772 | + $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
| 773 | + $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
| 774 | + |
|
| 775 | + $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 776 | + if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
| 777 | + |
|
| 778 | + // Check for prerequisite lesson for this quiz |
|
| 779 | + $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
| 780 | + $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
| 781 | + |
|
| 782 | + // Handle restrictions |
|
| 783 | + if( sensei_all_access() ) { |
|
| 784 | + $user_allowed = true; |
|
| 785 | + } else { |
|
| 786 | + if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
| 787 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 788 | + $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 789 | + $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
| 790 | + } else { |
|
| 791 | + $user_allowed = true; |
|
| 792 | + } // End If Statement |
|
| 793 | + } // End If Statement |
|
| 794 | + } elseif( $this->access_settings() ) { |
|
| 795 | + // Check if the user has started the course |
|
| 796 | + |
|
| 797 | + if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) { |
|
| 798 | + |
|
| 799 | + $user_allowed = false; |
|
| 800 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 801 | + $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 802 | + $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 803 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 804 | + $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 805 | + } else { |
|
| 806 | + $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 807 | + } // End If Statement |
|
| 808 | + } else { |
|
| 809 | + $user_allowed = true; |
|
| 810 | + } // End If Statement |
|
| 811 | + } else { |
|
| 812 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 813 | + $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 814 | + $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 815 | + } // End If Statement |
|
| 816 | + break; |
|
| 817 | + default: |
|
| 818 | + $user_allowed = true; |
|
| 819 | + break; |
|
| 820 | + |
|
| 821 | + } // End Switch Statement |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * filter the permissions message shown on sensei post types. |
|
| 825 | + * |
|
| 826 | + * @since 1.8.7 |
|
| 827 | + * |
|
| 828 | + * @param array $permissions_message{ |
|
| 829 | + * |
|
| 830 | + * @type string $title |
|
| 831 | + * @type string $message |
|
| 832 | + * |
|
| 833 | + * } |
|
| 834 | + * @param string $post_id |
|
| 835 | + */ |
|
| 836 | + $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
| 840 | + $user_allowed = true; |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + return apply_filters( 'sensei_access_permissions', $user_allowed ); |
|
| 844 | + } // End get_placeholder_image() |
|
| 845 | + |
|
| 846 | + |
|
| 847 | + /** |
|
| 848 | + * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
|
| 849 | + * @since 1.0.0 |
|
| 850 | + * @access public |
|
| 851 | + * @return void |
|
| 852 | + */ |
|
| 853 | + public function access_settings () { |
|
| 854 | + |
|
| 855 | + if( sensei_all_access() ) return true; |
|
| 856 | + |
|
| 857 | + if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
| 858 | + if ( is_user_logged_in() ) { |
|
| 859 | + return true; |
|
| 860 | + } else { |
|
| 861 | + return false; |
|
| 862 | + } // End If Statement |
|
| 863 | + } else { |
|
| 864 | + return true; |
|
| 865 | + } // End If Statement |
|
| 866 | + } // End access_settings() |
|
| 867 | + |
|
| 868 | + /** |
|
| 869 | + * sensei_woocommerce_complete_order description |
|
| 870 | + * @since 1.0.3 |
|
| 871 | + * @access public |
|
| 872 | + * @param int $order_id WC order ID |
|
| 873 | + * @return void |
|
| 874 | + */ |
|
| 875 | + public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
| 876 | + $order_user = array(); |
|
| 877 | + // Check for WooCommerce |
|
| 878 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 879 | + // Get order object |
|
| 880 | + $order = new WC_Order( $order_id ); |
|
| 881 | + $user = get_user_by( 'id', $order->user_id ); |
|
| 882 | + $order_user['ID'] = $user->ID; |
|
| 883 | + $order_user['user_login'] = $user->user_login; |
|
| 884 | + $order_user['user_email'] = $user->user_email; |
|
| 885 | + $order_user['user_url'] = $user->user_url; |
|
| 886 | + // Run through each product ordered |
|
| 887 | + if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 888 | + foreach( $order->get_items() as $item ) { |
|
| 889 | + $product_type = ''; |
|
| 890 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 891 | + $item_id = $item['variation_id']; |
|
| 892 | + $product_type = 'variation'; |
|
| 893 | + } else { |
|
| 894 | + $item_id = $item['product_id']; |
|
| 895 | + } // End If Statement |
|
| 896 | + $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 897 | + // Get courses that use the WC product |
|
| 898 | + $courses = $this->post_types->course->get_product_courses( $_product->id ); |
|
| 899 | + // Loop and update those courses |
|
| 900 | + foreach ( $courses as $course_item ) { |
|
| 901 | + $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 902 | + } // End For Loop |
|
| 903 | + } // End For Loop |
|
| 904 | + } // End If Statement |
|
| 905 | + // Add meta to indicate that payment has been completed successfully |
|
| 906 | + update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 907 | + } // End If Statement |
|
| 908 | + } // End sensei_woocommerce_complete_order() |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * Runs when an order is cancelled. |
|
| 912 | + * @since 1.2.0 |
|
| 913 | + * @access public |
|
| 914 | + * @param integer $order_id order ID |
|
| 915 | + * @return void |
|
| 916 | + */ |
|
| 917 | + public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
| 918 | + |
|
| 919 | + // Get order object |
|
| 920 | + $order = new WC_Order( $order_id ); |
|
| 921 | + |
|
| 922 | + // Run through each product ordered |
|
| 923 | + if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 924 | + |
|
| 925 | + // Get order user |
|
| 926 | + $user_id = $order->__get( 'user_id' ); |
|
| 927 | + |
|
| 928 | + foreach( $order->get_items() as $item ) { |
|
| 929 | + |
|
| 930 | + $product_type = ''; |
|
| 931 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 932 | + $item_id = $item['variation_id']; |
|
| 933 | + $product_type = 'variation'; |
|
| 934 | + } else { |
|
| 935 | + $item_id = $item['product_id']; |
|
| 936 | + } // End If Statement |
|
| 937 | + $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 938 | + |
|
| 939 | + // Get courses that use the WC product |
|
| 940 | + $courses = array(); |
|
| 941 | + $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 942 | + |
|
| 943 | + // Loop and update those courses |
|
| 944 | + foreach ($courses as $course_item){ |
|
| 945 | + // Check and Remove course from courses user meta |
|
| 946 | + $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 947 | + } // End For Loop |
|
| 948 | + } // End For Loop |
|
| 949 | + } // End If Statement |
|
| 950 | + } // End sensei_woocommerce_cancel_order() |
|
| 951 | + |
|
| 952 | + /** |
|
| 953 | + * Runs when an subscription is cancelled or expires. |
|
| 954 | + * @since 1.3.3 |
|
| 955 | + * @access public |
|
| 956 | + * @param integer $user_id User ID |
|
| 957 | + * @param integer $subscription_key Subscription Unique Key |
|
| 958 | + * @return void |
|
| 959 | + */ |
|
| 960 | + public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) { |
|
| 961 | + $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 962 | + self::sensei_woocommerce_cancel_order( $subscription['order_id'] ); |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + /** |
|
| 966 | + * Runs when an subscription is re-activated after suspension. |
|
| 967 | + * @since 1.3.3 |
|
| 968 | + * @access public |
|
| 969 | + * @param integer $user_id User ID |
|
| 970 | + * @param integer $subscription_key Subscription Unique Key |
|
| 971 | + * @return void |
|
| 972 | + */ |
|
| 973 | + public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) { |
|
| 974 | + $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 975 | + $order = new WC_Order( $subscription['order_id'] ); |
|
| 976 | + $user = get_user_by( 'id', $order->user_id ); |
|
| 977 | + $order_user = array(); |
|
| 978 | + $order_user['ID'] = $user->ID; |
|
| 979 | + $order_user['user_login'] = $user->user_login; |
|
| 980 | + $order_user['user_email'] = $user->user_email; |
|
| 981 | + $order_user['user_url'] = $user->user_url; |
|
| 982 | + $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] ); |
|
| 983 | + foreach ( $courses as $course_item ){ |
|
| 984 | + $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 985 | + } // End For Loop |
|
| 986 | + } // End sensei_woocommerce_reactivate_subscription |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * Returns the WooCommerce Product Object |
|
| 990 | + * |
|
| 991 | + * The code caters for pre and post WooCommerce 2.2 installations. |
|
| 992 | + * |
|
| 993 | + * @since 1.1.1 |
|
| 994 | + * @access public |
|
| 995 | + * @param integer $wc_product_id Product ID or Variation ID |
|
| 996 | + * @param string $product_type '' or 'variation' |
|
| 997 | + * @return WC_Product $wc_product_object |
|
| 998 | + */ |
|
| 999 | + public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1000 | + |
|
| 1001 | + $wc_product_object = false; |
|
| 1002 | + if ( 0 < intval( $wc_product_id ) ) { |
|
| 1003 | + |
|
| 1004 | + // Get the product |
|
| 1005 | + if ( function_exists( 'wc_get_product' ) ) { |
|
| 1006 | + |
|
| 1007 | + $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1008 | + |
|
| 1009 | + } elseif ( function_exists( 'get_product' ) ) { |
|
| 1010 | + |
|
| 1011 | + $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1012 | + |
|
| 1013 | + } else { |
|
| 1014 | + |
|
| 1015 | + // Pre WC 2.0 |
|
| 1016 | + if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1017 | + |
|
| 1018 | + $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1019 | + |
|
| 1020 | + } else { |
|
| 1021 | + |
|
| 1022 | + $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1023 | + |
|
| 1024 | + } // End If Statement |
|
| 1025 | + |
|
| 1026 | + } // End If Statement |
|
| 1027 | + |
|
| 1028 | + } // End If Statement |
|
| 1029 | + |
|
| 1030 | + return $wc_product_object; |
|
| 1031 | + |
|
| 1032 | + } // End sensei_get_woocommerce_product_object() |
|
| 1033 | + |
|
| 1034 | + /** |
|
| 1035 | + * load_class loads in class files |
|
| 1036 | + * @since 1.2.0 |
|
| 1037 | + * @access public |
|
| 1038 | + * @return void |
|
| 1039 | + */ |
|
| 1040 | + public function load_class ( $class_name = '' ) { |
|
| 1041 | + if ( '' != $class_name && '' != $this->token ) { |
|
| 1042 | + require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
| 1043 | + } // End If Statement |
|
| 1044 | + } // End load_class() |
|
| 1045 | + |
|
| 1046 | + /** |
|
| 1047 | + * sensei_activate_subscription runs when a subscription product is purchased |
|
| 1048 | + * @since 1.2.0 |
|
| 1049 | + * @access public |
|
| 1050 | + * @param integer $order_id order ID |
|
| 1051 | + * @return void |
|
| 1052 | + */ |
|
| 1053 | + public function sensei_activate_subscription( $order_id = 0 ) { |
|
| 1054 | + if ( 0 < intval( $order_id ) ) { |
|
| 1055 | + $order = new WC_Order( $order_id ); |
|
| 1056 | + $user = get_user_by('id', $order->user_id); |
|
| 1057 | + $order_user['ID'] = $user->ID; |
|
| 1058 | + $order_user['user_login'] = $user->user_login; |
|
| 1059 | + $order_user['user_email'] = $user->user_email; |
|
| 1060 | + $order_user['user_url'] = $user->user_url; |
|
| 1061 | + // Run through each product ordered |
|
| 1062 | + if (sizeof($order->get_items())>0) { |
|
| 1063 | + foreach($order->get_items() as $item) { |
|
| 1064 | + $product_type = ''; |
|
| 1065 | + if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
| 1066 | + $item_id = $item['variation_id']; |
|
| 1067 | + $product_type = 'subscription_variation'; |
|
| 1068 | + } else { |
|
| 1069 | + $item_id = $item['product_id']; |
|
| 1070 | + } // End If Statement |
|
| 1071 | + $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 1072 | + // Get courses that use the WC product |
|
| 1073 | + $courses = array(); |
|
| 1074 | + if ( $product_type == 'subscription_variation' ) { |
|
| 1075 | + $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 1076 | + } // End If Statement |
|
| 1077 | + // Loop and update those courses |
|
| 1078 | + foreach ($courses as $course_item){ |
|
| 1079 | + $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 1080 | + } // End For Loop |
|
| 1081 | + } // End For Loop |
|
| 1082 | + } // End If Statement |
|
| 1083 | + } // End If Statement |
|
| 1084 | + } // End sensei_activate_subscription() |
|
| 1085 | + |
|
| 1086 | + /** |
|
| 1087 | + * sensei_woocommerce_email_course_details adds detail to email |
|
| 1088 | + * @since 1.4.5 |
|
| 1089 | + * @access public |
|
| 1090 | + * @param WC_Order $order |
|
| 1091 | + * @return void |
|
| 1092 | + */ |
|
| 1093 | + public function sensei_woocommerce_email_course_details( $order ) { |
|
| 1094 | + global $woocommerce; |
|
| 1095 | + |
|
| 1096 | + // exit early if not wc-completed or wc-processing |
|
| 1097 | + if( 'wc-completed' != $order->post_status |
|
| 1098 | + && 'wc-processing' != $order->post_status ) { |
|
| 1099 | + return; |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + $order_items = $order->get_items(); |
|
| 1103 | + $order_id = $order->id; |
|
| 1104 | + |
|
| 1105 | + //If object have items go through them all to find course |
|
| 1106 | + if ( 0 < sizeof( $order_items ) ) { |
|
| 1107 | + |
|
| 1108 | + echo '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1109 | + |
|
| 1110 | + foreach ( $order_items as $item ) { |
|
| 1111 | + |
|
| 1112 | + $product_type = ''; |
|
| 1113 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1114 | + // If item has variation_id then its from variation |
|
| 1115 | + $item_id = $item['variation_id']; |
|
| 1116 | + $product_type = 'variation'; |
|
| 1117 | + } else { |
|
| 1118 | + // If not its real product set its id to item_id |
|
| 1119 | + $item_id = $item['product_id']; |
|
| 1120 | + } // End If Statement |
|
| 1121 | + |
|
| 1122 | + $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1123 | + |
|
| 1124 | + if( $user_id ) { |
|
| 1125 | + |
|
| 1126 | + // Get all courses for product |
|
| 1127 | + $args = array( |
|
| 1128 | + 'posts_per_page' => -1, |
|
| 1129 | + 'post_type' => 'course', |
|
| 1130 | + 'meta_query' => array( |
|
| 1131 | + array( |
|
| 1132 | + 'key' => '_course_woocommerce_product', |
|
| 1133 | + 'value' => $item_id |
|
| 1134 | + ) |
|
| 1135 | + ), |
|
| 1136 | + 'orderby' => 'menu_order date', |
|
| 1137 | + 'order' => 'ASC', |
|
| 1138 | + ); |
|
| 1139 | + $courses = get_posts( $args ); |
|
| 1140 | + |
|
| 1141 | + if( $courses && count( $courses ) > 0 ) { |
|
| 1142 | + |
|
| 1143 | + foreach( $courses as $course ) { |
|
| 1144 | + |
|
| 1145 | + $title = $course->post_title; |
|
| 1146 | + $permalink = get_permalink( $course->ID ); |
|
| 1147 | + |
|
| 1148 | + echo '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1149 | + } |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1152 | + } |
|
| 1153 | + } |
|
| 1154 | + } |
|
| 1155 | + |
|
| 1156 | + /** |
|
| 1157 | + * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
| 1158 | + * @since 1.4.0 |
|
| 1159 | + * @access public |
|
| 1160 | + * @param array $comments |
|
| 1161 | + * @param integer $post_id |
|
| 1162 | + * @return array |
|
| 1163 | + */ |
|
| 1164 | + public function sensei_count_comments( $comments, $post_id ) { |
|
| 1165 | + global $wpdb; |
|
| 1166 | + |
|
| 1167 | + $post_id = (int) $post_id; |
|
| 1168 | + |
|
| 1169 | + $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
| 1170 | + |
|
| 1171 | + if ( false !== $count ) { |
|
| 1172 | + return $count; |
|
| 1173 | + } |
|
| 1174 | + |
|
| 1175 | + $statuses = array( '' ); // Default to the WP normal comments |
|
| 1176 | + $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
| 1177 | + foreach ( (array) $stati AS $status ) { |
|
| 1178 | + if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
| 1179 | + $statuses[] = $status['comment_type']; |
|
| 1180 | + } |
|
| 1181 | + } |
|
| 1182 | + $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
| 1183 | + |
|
| 1184 | + if ( $post_id > 0 ) |
|
| 1185 | + $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1186 | + |
|
| 1187 | + $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 1188 | + |
|
| 1189 | + $total = 0; |
|
| 1190 | + $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
| 1191 | + foreach ( (array) $count as $row ) { |
|
| 1192 | + // Don't count post-trashed toward totals |
|
| 1193 | + if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 1194 | + $total += $row['num_comments']; |
|
| 1195 | + if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 1196 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + $stats['total_comments'] = $total; |
|
| 1200 | + foreach ( $approved as $key ) { |
|
| 1201 | + if ( empty($stats[$key]) ) |
|
| 1202 | + $stats[$key] = 0; |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + $stats = (object) $stats; |
|
| 1206 | + wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
| 1207 | + |
|
| 1208 | + return $stats; |
|
| 1209 | + } |
|
| 1210 | + |
|
| 1211 | + /** |
|
| 1212 | + * Init images. |
|
| 1213 | + * |
|
| 1214 | + * @since 1.4.5 |
|
| 1215 | + * @access public |
|
| 1216 | + * @return void |
|
| 1217 | + */ |
|
| 1218 | + public function init_image_sizes() { |
|
| 1219 | + $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
| 1220 | + $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
| 1221 | + $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
| 1222 | + $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
| 1223 | + |
|
| 1224 | + add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
| 1225 | + add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
| 1226 | + add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
| 1227 | + add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + /** |
|
| 1231 | + * Get an image size. |
|
| 1232 | + * |
|
| 1233 | + * Variable is filtered by sensei_get_image_size_{image_size} |
|
| 1234 | + * |
|
| 1235 | + * @since 1.4.5 |
|
| 1236 | + * @access public |
|
| 1237 | + * @param mixed $image_size |
|
| 1238 | + * @return string |
|
| 1239 | + */ |
|
| 1240 | + public function get_image_size( $image_size ) { |
|
| 1241 | + |
|
| 1242 | + // Only return sizes we define in settings |
|
| 1243 | + if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 1244 | + return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1245 | + |
|
| 1246 | + if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
| 1247 | + $this->settings->settings[ $image_size . '_width' ] = false; |
|
| 1248 | + } |
|
| 1249 | + if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
| 1250 | + $this->settings->settings[ $image_size . '_height' ] = false; |
|
| 1251 | + } |
|
| 1252 | + if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
| 1253 | + $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + $size = array_filter( array( |
|
| 1257 | + 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
| 1258 | + 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
| 1259 | + 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
| 1260 | + ) ); |
|
| 1261 | + |
|
| 1262 | + $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
| 1263 | + $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
| 1264 | + $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
| 1265 | + |
|
| 1266 | + return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + public function body_class( $classes ) { |
|
| 1270 | + if( is_sensei() ) { |
|
| 1271 | + $classes[] = 'sensei'; |
|
| 1272 | + } |
|
| 1273 | + return $classes; |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
| 1278 | + * |
|
| 1279 | + * @return null |
|
| 1280 | + * @since 1.7.0 |
|
| 1281 | + */ |
|
| 1282 | + public function jetpack_latex_support() { |
|
| 1283 | + if ( function_exists( 'latex_markup') ) { |
|
| 1284 | + add_filter( 'sensei_question_title', 'latex_markup' ); |
|
| 1285 | + add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
| 1286 | + } |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + /** |
|
| 1290 | + * Load the module functionality. |
|
| 1291 | + * |
|
| 1292 | + * This function is hooked into plugins_loaded to avoid conflicts with |
|
| 1293 | + * the retired modules extension. |
|
| 1294 | + * |
|
| 1295 | + * @since 1.8.0 |
|
| 1296 | + */ |
|
| 1297 | + public function load_modules_class(){ |
|
| 1298 | + global $sensei_modules; |
|
| 1299 | + |
|
| 1300 | + if( !class_exists( 'Sensei_Modules' ) |
|
| 1301 | + && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
| 1302 | + |
|
| 1303 | + //Load the modules class |
|
| 1304 | + require_once( 'class-sensei-modules.php'); |
|
| 1305 | + Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
| 1306 | + |
|
| 1307 | + }else{ |
|
| 1308 | + // fallback for people still using the modules extension. |
|
| 1309 | + global $sensei_modules; |
|
| 1310 | + Sensei()->modules = $sensei_modules; |
|
| 1311 | + add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
| 1312 | + } |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + /** |
|
| 1316 | + * Tell the user to that the modules extension is no longer needed. |
|
| 1317 | + * |
|
| 1318 | + * @since 1.8.0 |
|
| 1319 | + */ |
|
| 1320 | + public function disable_sensei_modules_extension(){ ?> |
|
| 1321 | 1321 | <div class="notice updated fade"> |
| 1322 | 1322 | <p> |
| 1323 | 1323 | <?php |
| 1324 | - $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
| 1325 | - $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
| 1326 | - ?> |
|
| 1324 | + $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
| 1325 | + $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
| 1326 | + ?> |
|
| 1327 | 1327 | <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension. |
| 1328 | 1328 | Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules). |
| 1329 | 1329 | </p> |
@@ -1331,46 +1331,46 @@ discard block |
||
| 1331 | 1331 | |
| 1332 | 1332 | <?php }// end function |
| 1333 | 1333 | |
| 1334 | - /** |
|
| 1335 | - * Sensei wide rewrite flush call. |
|
| 1336 | - * |
|
| 1337 | - * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
| 1338 | - * |
|
| 1339 | - * After the option is one the Rules will be flushed. |
|
| 1340 | - * |
|
| 1341 | - * @since 1.9.0 |
|
| 1342 | - */ |
|
| 1343 | - public function flush_rewrite_rules(){ |
|
| 1334 | + /** |
|
| 1335 | + * Sensei wide rewrite flush call. |
|
| 1336 | + * |
|
| 1337 | + * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
| 1338 | + * |
|
| 1339 | + * After the option is one the Rules will be flushed. |
|
| 1340 | + * |
|
| 1341 | + * @since 1.9.0 |
|
| 1342 | + */ |
|
| 1343 | + public function flush_rewrite_rules(){ |
|
| 1344 | 1344 | |
| 1345 | - // ensures that the rewrite rules are flushed on the second |
|
| 1346 | - // attempt. This ensure that the settings for any other process |
|
| 1347 | - // have been completed and saved to the database before we refresh the |
|
| 1348 | - // rewrite rules. |
|
| 1349 | - $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1350 | - if( '1' == $option ) { |
|
| 1345 | + // ensures that the rewrite rules are flushed on the second |
|
| 1346 | + // attempt. This ensure that the settings for any other process |
|
| 1347 | + // have been completed and saved to the database before we refresh the |
|
| 1348 | + // rewrite rules. |
|
| 1349 | + $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1350 | + if( '1' == $option ) { |
|
| 1351 | 1351 | |
| 1352 | - update_option('sensei_flush_rewrite_rules', '2'); |
|
| 1352 | + update_option('sensei_flush_rewrite_rules', '2'); |
|
| 1353 | 1353 | |
| 1354 | - }elseif( '2' == $option ) { |
|
| 1354 | + }elseif( '2' == $option ) { |
|
| 1355 | 1355 | |
| 1356 | - flush_rewrite_rules(); |
|
| 1357 | - update_option('sensei_flush_rewrite_rules', '0'); |
|
| 1356 | + flush_rewrite_rules(); |
|
| 1357 | + update_option('sensei_flush_rewrite_rules', '0'); |
|
| 1358 | 1358 | |
| 1359 | - } |
|
| 1359 | + } |
|
| 1360 | 1360 | |
| 1361 | - } // end flush_rewrite_rules |
|
| 1361 | + } // end flush_rewrite_rules |
|
| 1362 | 1362 | |
| 1363 | - /** |
|
| 1364 | - * Calling this function will tell Sensei to flush rewrite |
|
| 1365 | - * rules on the next load. |
|
| 1366 | - * |
|
| 1367 | - * @since 1.9.0 |
|
| 1368 | - */ |
|
| 1369 | - public function initiate_rewrite_rules_flush(){ |
|
| 1363 | + /** |
|
| 1364 | + * Calling this function will tell Sensei to flush rewrite |
|
| 1365 | + * rules on the next load. |
|
| 1366 | + * |
|
| 1367 | + * @since 1.9.0 |
|
| 1368 | + */ |
|
| 1369 | + public function initiate_rewrite_rules_flush(){ |
|
| 1370 | 1370 | |
| 1371 | - update_option('sensei_flush_rewrite_rules', '1'); |
|
| 1371 | + update_option('sensei_flush_rewrite_rules', '1'); |
|
| 1372 | 1372 | |
| 1373 | - } |
|
| 1373 | + } |
|
| 1374 | 1374 | |
| 1375 | 1375 | } // End Class |
| 1376 | 1376 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei_Main |
@@ -142,41 +142,41 @@ discard block |
||
| 142 | 142 | * @param string $file The base file of the plugin. |
| 143 | 143 | * @since 1.0.0 |
| 144 | 144 | */ |
| 145 | - public function __construct ( $file ) { |
|
| 145 | + public function __construct($file) { |
|
| 146 | 146 | |
| 147 | 147 | // Setup object data |
| 148 | 148 | $this->file = $file; |
| 149 | - $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
| 150 | - $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
| 151 | - $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
| 152 | - $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
| 149 | + $this->plugin_url = trailingslashit(plugins_url('', $plugin = $file)); |
|
| 150 | + $this->plugin_path = trailingslashit(dirname($file)); |
|
| 151 | + $this->template_url = apply_filters('sensei_template_url', 'sensei/'); |
|
| 152 | + $this->permissions_message = array('title' => __('Permission Denied', 'woothemes-sensei'), 'message' => __('Unfortunately you do not have permissions to access this page.', 'woothemes-sensei')); |
|
| 153 | 153 | |
| 154 | 154 | // Initialize the core Sensei functionality |
| 155 | 155 | $this->init(); |
| 156 | 156 | |
| 157 | 157 | // Installation |
| 158 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 158 | + if (is_admin() && ! defined('DOING_AJAX')) $this->install(); |
|
| 159 | 159 | |
| 160 | 160 | // Run this on activation. |
| 161 | - register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
| 161 | + register_activation_hook($this->file, array($this, 'activation')); |
|
| 162 | 162 | |
| 163 | 163 | // Setup post types. |
| 164 | 164 | $this->post_types = new Sensei_PostTypes(); |
| 165 | 165 | $this->post_types->token = 'woothemes-sensei-posttypes'; |
| 166 | 166 | |
| 167 | 167 | // Lad the updates class |
| 168 | - $this->updates = new WooThemes_Sensei_Updates( $this ); |
|
| 168 | + $this->updates = new WooThemes_Sensei_Updates($this); |
|
| 169 | 169 | |
| 170 | 170 | // Setup settings screen. |
| 171 | 171 | $this->settings = new Sensei_Settings(); |
| 172 | 172 | $this->settings->token = 'woothemes-sensei-settings'; |
| 173 | 173 | |
| 174 | 174 | // Setup Admin Settings data |
| 175 | - if ( is_admin() ) { |
|
| 175 | + if (is_admin()) { |
|
| 176 | 176 | |
| 177 | 177 | $this->settings->has_tabs = true; |
| 178 | - $this->settings->name = __( 'Sensei Settings', 'woothemes-sensei' ); |
|
| 179 | - $this->settings->menu_label = __( 'Settings', 'woothemes-sensei' ); |
|
| 178 | + $this->settings->name = __('Sensei Settings', 'woothemes-sensei'); |
|
| 179 | + $this->settings->menu_label = __('Settings', 'woothemes-sensei'); |
|
| 180 | 180 | $this->settings->page_slug = 'woothemes-sensei-settings'; |
| 181 | 181 | |
| 182 | 182 | } // End If Statement |
@@ -204,24 +204,24 @@ discard block |
||
| 204 | 204 | $this->quiz = $this->post_types->quiz; |
| 205 | 205 | |
| 206 | 206 | // load the modules class |
| 207 | - add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
| 207 | + add_action('plugins_loaded', array($this, 'load_modules_class')); |
|
| 208 | 208 | |
| 209 | 209 | // Load Learner Management Functionality |
| 210 | - $this->learners = new Sensei_Learners( $file ); |
|
| 210 | + $this->learners = new Sensei_Learners($file); |
|
| 211 | 211 | $this->learners->token = $this->token; |
| 212 | 212 | |
| 213 | 213 | // Differentiate between administration and frontend logic. |
| 214 | - if ( is_admin() ) { |
|
| 214 | + if (is_admin()) { |
|
| 215 | 215 | |
| 216 | 216 | // Load Admin Welcome class |
| 217 | 217 | new Sensei_Welcome(); |
| 218 | 218 | |
| 219 | 219 | // Load Admin Class |
| 220 | - $this->admin = new Sensei_Admin( $file ); |
|
| 220 | + $this->admin = new Sensei_Admin($file); |
|
| 221 | 221 | $this->admin->token = $this->token; |
| 222 | 222 | |
| 223 | 223 | // Load Analysis Reports |
| 224 | - $this->analysis = new Sensei_Analysis( $file ); |
|
| 224 | + $this->analysis = new Sensei_Analysis($file); |
|
| 225 | 225 | $this->analysis->token = $this->token; |
| 226 | 226 | |
| 227 | 227 | |
@@ -238,11 +238,11 @@ discard block |
||
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | // Load Grading Functionality |
| 241 | - $this->grading = new Sensei_Grading( $file ); |
|
| 241 | + $this->grading = new Sensei_Grading($file); |
|
| 242 | 242 | $this->grading->token = $this->token; |
| 243 | 243 | |
| 244 | 244 | // Load Email Class |
| 245 | - $this->emails = new Sensei_Emails( $file ); |
|
| 245 | + $this->emails = new Sensei_Emails($file); |
|
| 246 | 246 | $this->emails->token = $this->token; |
| 247 | 247 | |
| 248 | 248 | // Load Learner Profiles Class |
@@ -254,38 +254,38 @@ discard block |
||
| 254 | 254 | |
| 255 | 255 | // Force WooCommerce Required Settings |
| 256 | 256 | $this->set_woocommerce_functionality(); |
| 257 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 258 | - add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
| 257 | + add_action('widgets_init', array($this, 'register_widgets')); |
|
| 258 | + add_action('after_setup_theme', array($this, 'ensure_post_thumbnails_support')); |
|
| 259 | 259 | |
| 260 | 260 | // WooCommerce Payment Actions |
| 261 | - add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 262 | - add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 263 | - add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 264 | - add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 265 | - add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 266 | - add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 267 | - add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) ); |
|
| 261 | + add_action('woocommerce_payment_complete', array($this, 'sensei_woocommerce_complete_order')); |
|
| 262 | + add_action('woocommerce_thankyou', array($this, 'sensei_woocommerce_complete_order')); |
|
| 263 | + add_action('woocommerce_order_status_completed', array($this, 'sensei_woocommerce_complete_order')); |
|
| 264 | + add_action('woocommerce_order_status_processing', array($this, 'sensei_woocommerce_complete_order')); |
|
| 265 | + add_action('woocommerce_order_status_cancelled', array($this, 'sensei_woocommerce_cancel_order')); |
|
| 266 | + add_action('woocommerce_order_status_refunded', array($this, 'sensei_woocommerce_cancel_order')); |
|
| 267 | + add_action('subscriptions_activated_for_order', array($this, 'sensei_activate_subscription')); |
|
| 268 | 268 | |
| 269 | 269 | // WooCommerce Subscriptions Actions |
| 270 | - add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 ); |
|
| 271 | - add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 272 | - add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 273 | - add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 274 | - add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 270 | + add_action('reactivated_subscription', array($this, 'sensei_woocommerce_reactivate_subscription'), 10, 2); |
|
| 271 | + add_action('subscription_expired', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2); |
|
| 272 | + add_action('subscription_end_of_prepaid_term', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2); |
|
| 273 | + add_action('cancelled_subscription', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2); |
|
| 274 | + add_action('subscription_put_on-hold', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2); |
|
| 275 | 275 | |
| 276 | 276 | // Add Email link to course orders |
| 277 | - add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 ); |
|
| 277 | + add_action('woocommerce_email_after_order_table', array($this, 'sensei_woocommerce_email_course_details'), 10, 1); |
|
| 278 | 278 | |
| 279 | 279 | // Filter comment counts |
| 280 | - add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
| 280 | + add_filter('wp_count_comments', array($this, 'sensei_count_comments'), 10, 2); |
|
| 281 | 281 | |
| 282 | - add_action( 'body_class', array( $this, 'body_class' ) ); |
|
| 282 | + add_action('body_class', array($this, 'body_class')); |
|
| 283 | 283 | |
| 284 | 284 | // Check for and activate JetPack LaTeX support |
| 285 | - add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
| 285 | + add_action('plugins_loaded', array($this, 'jetpack_latex_support'), 200); // Runs after Jetpack has loaded it's modules |
|
| 286 | 286 | |
| 287 | 287 | // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
| 288 | - add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
| 288 | + add_action('init', array($this, 'flush_rewrite_rules'), 101); |
|
| 289 | 289 | |
| 290 | 290 | } // End __construct() |
| 291 | 291 | |
@@ -293,11 +293,11 @@ discard block |
||
| 293 | 293 | * Load the foundations of Sensei. |
| 294 | 294 | * @since 1.9.0 |
| 295 | 295 | */ |
| 296 | - protected function init(){ |
|
| 296 | + protected function init() { |
|
| 297 | 297 | |
| 298 | 298 | // Localisation |
| 299 | 299 | $this->load_plugin_textdomain(); |
| 300 | - add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
| 300 | + add_action('init', array($this, 'load_localisation'), 0); |
|
| 301 | 301 | |
| 302 | 302 | // load the shortcode loader into memory, so as to listen to all for |
| 303 | 303 | // all shortcodes on the front end |
@@ -313,9 +313,9 @@ discard block |
||
| 313 | 313 | * |
| 314 | 314 | * @param $plugin |
| 315 | 315 | */ |
| 316 | - public static function activation_flush_rules( $plugin ){ |
|
| 316 | + public static function activation_flush_rules($plugin) { |
|
| 317 | 317 | |
| 318 | - if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
| 318 | + if (strpos($plugin, '/woothemes-sensei.php') > 0) { |
|
| 319 | 319 | |
| 320 | 320 | flush_rewrite_rules(true); |
| 321 | 321 | |
@@ -335,12 +335,12 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | public static function instance() { |
| 337 | 337 | |
| 338 | - if ( is_null( self::$_instance ) ) { |
|
| 338 | + if (is_null(self::$_instance)) { |
|
| 339 | 339 | |
| 340 | 340 | //Sensei requires a reference to the main Sensei plugin file |
| 341 | - $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
| 341 | + $sensei_main_plugin_file = dirname(dirname(__FILE__)).'/woothemes-sensei.php'; |
|
| 342 | 342 | |
| 343 | - self::$_instance = new self( $sensei_main_plugin_file ); |
|
| 343 | + self::$_instance = new self($sensei_main_plugin_file); |
|
| 344 | 344 | |
| 345 | 345 | } |
| 346 | 346 | |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | * @since 1.8.0 |
| 354 | 354 | */ |
| 355 | 355 | public function __clone() { |
| 356 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 356 | + _doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'woothemes-sensei'), '2.1'); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | * @since 1.8.0 |
| 362 | 362 | */ |
| 363 | 363 | public function __wakeup() { |
| 364 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 364 | + _doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'woothemes-sensei'), '2.1'); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | public function run_updates() { |
| 374 | 374 | // Run updates if administrator |
| 375 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
| 375 | + if (current_user_can('manage_options') || current_user_can('manage_sensei')) { |
|
| 376 | 376 | |
| 377 | 377 | $this->updates->update(); |
| 378 | 378 | |
@@ -387,10 +387,10 @@ discard block |
||
| 387 | 387 | */ |
| 388 | 388 | public function set_woocommerce_functionality() { |
| 389 | 389 | // Disable guest checkout if a course is in the cart as we need a valid user to store data for |
| 390 | - add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) ); |
|
| 390 | + add_filter('pre_option_woocommerce_enable_guest_checkout', array($this, 'disable_guest_checkout')); |
|
| 391 | 391 | |
| 392 | 392 | // Mark orders with virtual products as complete rather then stay processing |
| 393 | - add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 ); |
|
| 393 | + add_filter('woocommerce_payment_complete_order_status', array($this, 'virtual_order_payment_complete'), 10, 2); |
|
| 394 | 394 | |
| 395 | 395 | } // End set_woocommerce_functionality() |
| 396 | 396 | |
@@ -399,14 +399,14 @@ discard block |
||
| 399 | 399 | * @param boolean $guest_checkout Current guest checkout setting |
| 400 | 400 | * @return boolean Modified guest checkout setting |
| 401 | 401 | */ |
| 402 | - public function disable_guest_checkout( $guest_checkout ) { |
|
| 402 | + public function disable_guest_checkout($guest_checkout) { |
|
| 403 | 403 | global $woocommerce; |
| 404 | 404 | |
| 405 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 405 | + if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 406 | 406 | |
| 407 | - if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) { |
|
| 408 | - foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) { |
|
| 409 | - if( isset( $product['product_id'] ) ) { |
|
| 407 | + if (isset($woocommerce->cart->cart_contents) && count($woocommerce->cart->cart_contents) > 0) { |
|
| 408 | + foreach ($woocommerce->cart->cart_contents as $cart_key => $product) { |
|
| 409 | + if (isset($product['product_id'])) { |
|
| 410 | 410 | $args = array( |
| 411 | 411 | 'posts_per_page' => -1, |
| 412 | 412 | 'post_type' => 'course', |
@@ -417,9 +417,9 @@ discard block |
||
| 417 | 417 | ) |
| 418 | 418 | ) |
| 419 | 419 | ); |
| 420 | - $posts = get_posts( $args ); |
|
| 421 | - if( $posts && count( $posts ) > 0 ) { |
|
| 422 | - foreach( $posts as $course ) { |
|
| 420 | + $posts = get_posts($args); |
|
| 421 | + if ($posts && count($posts) > 0) { |
|
| 422 | + foreach ($posts as $course) { |
|
| 423 | 423 | $guest_checkout = ''; |
| 424 | 424 | break; |
| 425 | 425 | } |
@@ -439,17 +439,17 @@ discard block |
||
| 439 | 439 | * @param int $order_id |
| 440 | 440 | * @return string |
| 441 | 441 | **/ |
| 442 | - public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 443 | - $order = new WC_Order( $order_id ); |
|
| 444 | - if ( ! isset ( $order ) ) return; |
|
| 445 | - if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 442 | + public function virtual_order_payment_complete($order_status, $order_id) { |
|
| 443 | + $order = new WC_Order($order_id); |
|
| 444 | + if ( ! isset ($order)) return; |
|
| 445 | + if ($order_status == 'wc-processing' && ($order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed')) { |
|
| 446 | 446 | $virtual_order = true; |
| 447 | 447 | |
| 448 | - if ( count( $order->get_items() ) > 0 ) { |
|
| 449 | - foreach( $order->get_items() as $item ) { |
|
| 450 | - if ( $item['product_id'] > 0 ) { |
|
| 451 | - $_product = $order->get_product_from_item( $item ); |
|
| 452 | - if ( ! $_product->is_virtual() ) { |
|
| 448 | + if (count($order->get_items()) > 0) { |
|
| 449 | + foreach ($order->get_items() as $item) { |
|
| 450 | + if ($item['product_id'] > 0) { |
|
| 451 | + $_product = $order->get_product_from_item($item); |
|
| 452 | + if ( ! $_product->is_virtual()) { |
|
| 453 | 453 | $virtual_order = false; |
| 454 | 454 | break; |
| 455 | 455 | } // End If Statement |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | } // End If Statement |
| 459 | 459 | |
| 460 | 460 | // virtual order, mark as completed |
| 461 | - if ( $virtual_order ) { |
|
| 461 | + if ($virtual_order) { |
|
| 462 | 462 | return 'completed'; |
| 463 | 463 | } // End If Statement |
| 464 | 464 | } // End If Statement |
@@ -471,21 +471,21 @@ discard block |
||
| 471 | 471 | * @since 1.0.0 |
| 472 | 472 | * @return void |
| 473 | 473 | */ |
| 474 | - public function register_widgets () { |
|
| 474 | + public function register_widgets() { |
|
| 475 | 475 | // Widget List (key => value is filename => widget class). |
| 476 | - $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
| 476 | + $widget_list = apply_filters('sensei_registered_widgets_list', array('course-component' => 'Course_Component', |
|
| 477 | 477 | 'lesson-component' => 'Lesson_Component', |
| 478 | 478 | 'course-categories' => 'Course_Categories', |
| 479 | - 'category-courses' => 'Category_Courses' ) |
|
| 479 | + 'category-courses' => 'Category_Courses') |
|
| 480 | 480 | ); |
| 481 | - foreach ( $widget_list as $key => $value ) { |
|
| 482 | - if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ) ) { |
|
| 483 | - require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ); |
|
| 484 | - register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
| 481 | + foreach ($widget_list as $key => $value) { |
|
| 482 | + if (file_exists($this->plugin_path.'widgets/widget-woothemes-sensei-'.esc_attr($key).'.php')) { |
|
| 483 | + require_once($this->plugin_path.'widgets/widget-woothemes-sensei-'.esc_attr($key).'.php'); |
|
| 484 | + register_widget('WooThemes_Sensei_'.$value.'_Widget'); |
|
| 485 | 485 | } |
| 486 | 486 | } // End For Loop |
| 487 | 487 | |
| 488 | - do_action( 'sensei_register_widgets' ); |
|
| 488 | + do_action('sensei_register_widgets'); |
|
| 489 | 489 | } // End register_widgets() |
| 490 | 490 | |
| 491 | 491 | /** |
@@ -494,8 +494,8 @@ discard block |
||
| 494 | 494 | * @since 1.0.0 |
| 495 | 495 | * @return void |
| 496 | 496 | */ |
| 497 | - public function load_localisation () { |
|
| 498 | - load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 497 | + public function load_localisation() { |
|
| 498 | + load_plugin_textdomain('woothemes-sensei', false, dirname(plugin_basename($this->file)).'/lang/'); |
|
| 499 | 499 | } // End load_localisation() |
| 500 | 500 | |
| 501 | 501 | /** |
@@ -504,12 +504,12 @@ discard block |
||
| 504 | 504 | * @since 1.0.0 |
| 505 | 505 | * @return void |
| 506 | 506 | */ |
| 507 | - public function load_plugin_textdomain () { |
|
| 507 | + public function load_plugin_textdomain() { |
|
| 508 | 508 | $domain = 'woothemes-sensei'; |
| 509 | 509 | // The "plugin_locale" filter is also used in load_plugin_textdomain() |
| 510 | - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 511 | - load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
| 512 | - load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 510 | + $locale = apply_filters('plugin_locale', get_locale(), $domain); |
|
| 511 | + load_textdomain($domain, WP_LANG_DIR.'/'.$domain.'/'.$domain.'-'.$locale.'.mo'); |
|
| 512 | + load_plugin_textdomain($domain, FALSE, dirname(plugin_basename($this->file)).'/lang/'); |
|
| 513 | 513 | } // End load_plugin_textdomain() |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | * @since 1.0.0 |
| 519 | 519 | * @return void |
| 520 | 520 | */ |
| 521 | - public function activation () { |
|
| 521 | + public function activation() { |
|
| 522 | 522 | $this->register_plugin_version(); |
| 523 | 523 | } // End activation() |
| 524 | 524 | |
@@ -529,9 +529,9 @@ discard block |
||
| 529 | 529 | * @since 1.0.0 |
| 530 | 530 | * @return void |
| 531 | 531 | */ |
| 532 | - public function install () { |
|
| 533 | - register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
| 534 | - register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
| 532 | + public function install() { |
|
| 533 | + register_activation_hook($this->file, array($this, 'activate_sensei')); |
|
| 534 | + register_activation_hook($this->file, 'flush_rewrite_rules'); |
|
| 535 | 535 | } // End install() |
| 536 | 536 | |
| 537 | 537 | |
@@ -541,9 +541,9 @@ discard block |
||
| 541 | 541 | * @since 1.0.0 |
| 542 | 542 | * @return void |
| 543 | 543 | */ |
| 544 | - public function activate_sensei () { |
|
| 545 | - update_option( 'skip_install_sensei_pages', 0 ); |
|
| 546 | - update_option( 'sensei_installed', 1 ); |
|
| 544 | + public function activate_sensei() { |
|
| 545 | + update_option('skip_install_sensei_pages', 0); |
|
| 546 | + update_option('sensei_installed', 1); |
|
| 547 | 547 | } // End activate_sensei() |
| 548 | 548 | |
| 549 | 549 | /** |
@@ -552,8 +552,8 @@ discard block |
||
| 552 | 552 | * @since 1.0.0 |
| 553 | 553 | * @return void |
| 554 | 554 | */ |
| 555 | - private function register_plugin_version () { |
|
| 556 | - if ( $this->version != '' ) { |
|
| 555 | + private function register_plugin_version() { |
|
| 556 | + if ($this->version != '') { |
|
| 557 | 557 | |
| 558 | 558 | // Check previous version to see if forced updates must run |
| 559 | 559 | // $old_version = get_option( 'woothemes-sensei-version', false ); |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | // delete_option( 'woothemes-sensei-force-updates' ); |
| 564 | 564 | // } |
| 565 | 565 | |
| 566 | - update_option( 'woothemes-sensei-version', $this->version ); |
|
| 566 | + update_option('woothemes-sensei-version', $this->version); |
|
| 567 | 567 | } |
| 568 | 568 | } // End register_plugin_version() |
| 569 | 569 | |
@@ -573,8 +573,8 @@ discard block |
||
| 573 | 573 | * @since 1.0.1 |
| 574 | 574 | * @return void |
| 575 | 575 | */ |
| 576 | - public function ensure_post_thumbnails_support () { |
|
| 577 | - if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
| 576 | + public function ensure_post_thumbnails_support() { |
|
| 577 | + if ( ! current_theme_supports('post-thumbnails')) { add_theme_support('post-thumbnails'); } |
|
| 578 | 578 | } // End ensure_post_thumbnails_support() |
| 579 | 579 | |
| 580 | 580 | |
@@ -586,10 +586,10 @@ discard block |
||
| 586 | 586 | * @return void |
| 587 | 587 | * @deprecated |
| 588 | 588 | */ |
| 589 | - public function template_loader ( $template = '' ) { |
|
| 589 | + public function template_loader($template = '') { |
|
| 590 | 590 | |
| 591 | - _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
| 592 | - return Sensei_Templates::template_loader( $template ); |
|
| 591 | + _deprecated_function('Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead'); |
|
| 592 | + return Sensei_Templates::template_loader($template); |
|
| 593 | 593 | |
| 594 | 594 | } // End template_loader() |
| 595 | 595 | |
@@ -599,15 +599,15 @@ discard block |
||
| 599 | 599 | * @since 1.0.0 |
| 600 | 600 | * @return string $sensei_plugin_path |
| 601 | 601 | */ |
| 602 | - public function plugin_path () { |
|
| 602 | + public function plugin_path() { |
|
| 603 | 603 | |
| 604 | - if ( $this->plugin_path ) { |
|
| 604 | + if ($this->plugin_path) { |
|
| 605 | 605 | |
| 606 | - $sensei_plugin_path = $this->plugin_path; |
|
| 606 | + $sensei_plugin_path = $this->plugin_path; |
|
| 607 | 607 | |
| 608 | - }else{ |
|
| 608 | + } else { |
|
| 609 | 609 | |
| 610 | - $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
| 610 | + $sensei_plugin_path = plugin_dir_path(__FILE__); |
|
| 611 | 611 | |
| 612 | 612 | } |
| 613 | 613 | |
@@ -623,9 +623,9 @@ discard block |
||
| 623 | 623 | * @param string $page |
| 624 | 624 | * @return int |
| 625 | 625 | */ |
| 626 | - public function get_page_id ( $page ) { |
|
| 627 | - $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
| 628 | - return ( $page ) ? $page : -1; |
|
| 626 | + public function get_page_id($page) { |
|
| 627 | + $page = apply_filters('sensei_get_'.esc_attr($page).'_page_id', get_option('sensei_'.esc_attr($page).'_page_id')); |
|
| 628 | + return ($page) ? $page : -1; |
|
| 629 | 629 | } // End get_page_id() |
| 630 | 630 | |
| 631 | 631 | |
@@ -637,18 +637,18 @@ discard block |
||
| 637 | 637 | * @param array/Object $order_user (default: array()) Specific user's data. |
| 638 | 638 | * @return void |
| 639 | 639 | */ |
| 640 | - public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
| 640 | + public function woocommerce_course_update($course_id = 0, $order_user = array()) { |
|
| 641 | 641 | global $current_user; |
| 642 | 642 | |
| 643 | - if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return; |
|
| 643 | + if ( ! isset($current_user) || ! $current_user->ID > 0) return; |
|
| 644 | 644 | |
| 645 | 645 | $data_update = false; |
| 646 | 646 | |
| 647 | 647 | // Get the product ID |
| 648 | - $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 648 | + $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true); |
|
| 649 | 649 | |
| 650 | 650 | // Check if in the admin |
| 651 | - if ( is_admin() ) { |
|
| 651 | + if (is_admin()) { |
|
| 652 | 652 | $user_login = $order_user['user_login']; |
| 653 | 653 | $user_email = $order_user['user_email']; |
| 654 | 654 | $user_url = $order_user['user_url']; |
@@ -661,25 +661,25 @@ discard block |
||
| 661 | 661 | } // End If Statement |
| 662 | 662 | |
| 663 | 663 | // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
| 664 | - $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 665 | - if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 666 | - $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 667 | - if ( ! $prereq_course_complete ) { |
|
| 664 | + $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true); |
|
| 665 | + if (0 < absint($course_prerequisite_id)) { |
|
| 666 | + $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id)); |
|
| 667 | + if ( ! $prereq_course_complete) { |
|
| 668 | 668 | // Remove all course user meta |
| 669 | - return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 669 | + return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id); |
|
| 670 | 670 | } |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | - $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 673 | + $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id)); |
|
| 674 | 674 | |
| 675 | - if( ! $is_user_taking_course ) { |
|
| 675 | + if ( ! $is_user_taking_course) { |
|
| 676 | 676 | |
| 677 | - if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
| 677 | + if (Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product($user_email, $user_id, $wc_post_id) && (0 < $wc_post_id)) { |
|
| 678 | 678 | |
| 679 | - $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
| 679 | + $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id)); |
|
| 680 | 680 | |
| 681 | 681 | $is_user_taking_course = false; |
| 682 | - if ( true == $activity_logged ) { |
|
| 682 | + if (true == $activity_logged) { |
|
| 683 | 683 | $is_user_taking_course = true; |
| 684 | 684 | } // End If Statement |
| 685 | 685 | } // End If Statement |
@@ -697,14 +697,14 @@ discard block |
||
| 697 | 697 | * @param array $data (default: array()) |
| 698 | 698 | * @return bool |
| 699 | 699 | */ |
| 700 | - public function check_user_permissions ( $page = '', $data = array() ) { |
|
| 700 | + public function check_user_permissions($page = '', $data = array()) { |
|
| 701 | 701 | // REFACTOR |
| 702 | 702 | global $current_user, $post; |
| 703 | 703 | |
| 704 | 704 | // if use is not logged in |
| 705 | - if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') ){ |
|
| 706 | - $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
| 707 | - $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
| 705 | + if (empty($current_user->caps) && Sensei()->settings->get('access_permission')) { |
|
| 706 | + $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei'); |
|
| 707 | + $this->permissions_message['message'] = sprintf(__('You must be logged in to view this %s'), get_post_type()); |
|
| 708 | 708 | return; |
| 709 | 709 | } |
| 710 | 710 | |
@@ -714,104 +714,104 @@ discard block |
||
| 714 | 714 | |
| 715 | 715 | $user_allowed = false; |
| 716 | 716 | |
| 717 | - switch ( $page ) { |
|
| 717 | + switch ($page) { |
|
| 718 | 718 | case 'course-single': |
| 719 | 719 | // check for prerequisite course or lesson, |
| 720 | - $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
| 721 | - $update_course = $this->woocommerce_course_update( $post->ID ); |
|
| 720 | + $course_prerequisite_id = (int) get_post_meta($post->ID, '_course_prerequisite', true); |
|
| 721 | + $update_course = $this->woocommerce_course_update($post->ID); |
|
| 722 | 722 | // Count completed lessons |
| 723 | - if ( 0 < absint( $course_prerequisite_id ) ) { |
|
| 723 | + if (0 < absint($course_prerequisite_id)) { |
|
| 724 | 724 | |
| 725 | - $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
| 725 | + $prerequisite_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, $current_user->ID); |
|
| 726 | 726 | |
| 727 | 727 | } |
| 728 | 728 | else { |
| 729 | 729 | $prerequisite_complete = true; |
| 730 | 730 | } // End If Statement |
| 731 | 731 | // Handles restrictions |
| 732 | - if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
| 733 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 734 | - $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 735 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
| 732 | + if ( ! $prerequisite_complete && 0 < absint($course_prerequisite_id)) { |
|
| 733 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 734 | + $course_link = '<a href="'.esc_url(get_permalink($course_prerequisite_id)).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
| 735 | + $this->permissions_message['message'] = sprintf(__('Please complete the previous %1$s before taking this course.', 'woothemes-sensei'), $course_link); |
|
| 736 | 736 | } else { |
| 737 | 737 | $user_allowed = true; |
| 738 | 738 | } // End If Statement |
| 739 | 739 | break; |
| 740 | 740 | case 'lesson-single': |
| 741 | 741 | // Check for WC purchase |
| 742 | - $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
| 742 | + $lesson_course_id = get_post_meta($post->ID, '_lesson_course', true); |
|
| 743 | 743 | |
| 744 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 745 | - $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
| 746 | - if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 744 | + $update_course = $this->woocommerce_course_update($lesson_course_id); |
|
| 745 | + $is_preview = Sensei_Utils::is_preview_lesson($post->ID); |
|
| 746 | + if ($this->access_settings() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) { |
|
| 747 | 747 | $user_allowed = true; |
| 748 | - } elseif( $this->access_settings() && false == $is_preview ) { |
|
| 748 | + } elseif ($this->access_settings() && false == $is_preview) { |
|
| 749 | 749 | |
| 750 | 750 | $user_allowed = true; |
| 751 | 751 | } else { |
| 752 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 753 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 754 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 755 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 756 | - if ( $is_preview ) { |
|
| 757 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 752 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 753 | + $course_link = '<a href="'.esc_url(get_permalink($lesson_course_id)).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
| 754 | + $wc_post_id = get_post_meta($lesson_course_id, '_course_woocommerce_product', true); |
|
| 755 | + if (Sensei_WC::is_woocommerce_active() && (0 < $wc_post_id)) { |
|
| 756 | + if ($is_preview) { |
|
| 757 | + $this->permissions_message['message'] = sprintf(__('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei'), $course_link); |
|
| 758 | 758 | } else { |
| 759 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 759 | + $this->permissions_message['message'] = sprintf(__('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei'), $course_link); |
|
| 760 | 760 | } |
| 761 | 761 | } else { |
| 762 | - if ( $is_preview ) { |
|
| 763 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 762 | + if ($is_preview) { |
|
| 763 | + $this->permissions_message['message'] = sprintf(__('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei'), $course_link); |
|
| 764 | 764 | } else { |
| 765 | 765 | /** This filter is documented in class-woothemes-sensei-frontend.php */ |
| 766 | - $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 766 | + $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei'), $course_link); |
|
| 767 | 767 | } |
| 768 | 768 | } // End If Statement |
| 769 | 769 | } // End If Statement |
| 770 | 770 | break; |
| 771 | 771 | case 'quiz-single': |
| 772 | - $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
| 773 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
| 772 | + $lesson_id = get_post_meta($post->ID, '_quiz_lesson', true); |
|
| 773 | + $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 774 | 774 | |
| 775 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 776 | - if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
| 775 | + $update_course = $this->woocommerce_course_update($lesson_course_id); |
|
| 776 | + if (($this->access_settings() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) || sensei_all_access()) { |
|
| 777 | 777 | |
| 778 | 778 | // Check for prerequisite lesson for this quiz |
| 779 | - $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
| 780 | - $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
| 779 | + $lesson_prerequisite_id = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true); |
|
| 780 | + $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson($lesson_prerequisite_id, $current_user->ID); |
|
| 781 | 781 | |
| 782 | 782 | // Handle restrictions |
| 783 | - if( sensei_all_access() ) { |
|
| 783 | + if (sensei_all_access()) { |
|
| 784 | 784 | $user_allowed = true; |
| 785 | 785 | } else { |
| 786 | - if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
| 787 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 788 | - $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 789 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
| 786 | + if (0 < absint($lesson_prerequisite_id) && ( ! $user_lesson_prerequisite_complete)) { |
|
| 787 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 788 | + $lesson_link = '<a href="'.esc_url(get_permalink($lesson_prerequisite_id)).'">'.__('lesson', 'woothemes-sensei').'</a>'; |
|
| 789 | + $this->permissions_message['message'] = sprintf(__('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei'), $lesson_link); |
|
| 790 | 790 | } else { |
| 791 | 791 | $user_allowed = true; |
| 792 | 792 | } // End If Statement |
| 793 | 793 | } // End If Statement |
| 794 | - } elseif( $this->access_settings() ) { |
|
| 794 | + } elseif ($this->access_settings()) { |
|
| 795 | 795 | // Check if the user has started the course |
| 796 | 796 | |
| 797 | - if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) { |
|
| 797 | + if (is_user_logged_in() && ! Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID) && (isset($this->settings->settings['access_permission']) && (true == $this->settings->settings['access_permission']))) { |
|
| 798 | 798 | |
| 799 | 799 | $user_allowed = false; |
| 800 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 801 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 802 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 803 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 804 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 800 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 801 | + $course_link = '<a href="'.esc_url(get_permalink($lesson_course_id)).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
| 802 | + $wc_post_id = get_post_meta($lesson_course_id, '_course_woocommerce_product', true); |
|
| 803 | + if (Sensei_WC::is_woocommerce_active() && (0 < $wc_post_id)) { |
|
| 804 | + $this->permissions_message['message'] = sprintf(__('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei'), $course_link); |
|
| 805 | 805 | } else { |
| 806 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 806 | + $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei'), $course_link); |
|
| 807 | 807 | } // End If Statement |
| 808 | 808 | } else { |
| 809 | 809 | $user_allowed = true; |
| 810 | 810 | } // End If Statement |
| 811 | 811 | } else { |
| 812 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 813 | - $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 814 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 812 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 813 | + $course_link = '<a href="'.esc_url(get_permalink(get_post_meta(get_post_meta($post->ID, '_quiz_lesson', true), '_lesson_course', true))).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
| 814 | + $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei'), $course_link); |
|
| 815 | 815 | } // End If Statement |
| 816 | 816 | break; |
| 817 | 817 | default: |
@@ -833,14 +833,14 @@ discard block |
||
| 833 | 833 | * } |
| 834 | 834 | * @param string $post_id |
| 835 | 835 | */ |
| 836 | - $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
| 836 | + $this->permissions_message = apply_filters('sensei_permissions_message', $this->permissions_message, $post->ID); |
|
| 837 | 837 | |
| 838 | 838 | |
| 839 | - if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
| 839 | + if (sensei_all_access() || Sensei_Utils::is_preview_lesson($post->ID)) { |
|
| 840 | 840 | $user_allowed = true; |
| 841 | 841 | } |
| 842 | 842 | |
| 843 | - return apply_filters( 'sensei_access_permissions', $user_allowed ); |
|
| 843 | + return apply_filters('sensei_access_permissions', $user_allowed); |
|
| 844 | 844 | } // End get_placeholder_image() |
| 845 | 845 | |
| 846 | 846 | |
@@ -850,12 +850,12 @@ discard block |
||
| 850 | 850 | * @access public |
| 851 | 851 | * @return void |
| 852 | 852 | */ |
| 853 | - public function access_settings () { |
|
| 853 | + public function access_settings() { |
|
| 854 | 854 | |
| 855 | - if( sensei_all_access() ) return true; |
|
| 855 | + if (sensei_all_access()) return true; |
|
| 856 | 856 | |
| 857 | - if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
| 858 | - if ( is_user_logged_in() ) { |
|
| 857 | + if (isset($this->settings->settings['access_permission']) && (true == $this->settings->settings['access_permission'])) { |
|
| 858 | + if (is_user_logged_in()) { |
|
| 859 | 859 | return true; |
| 860 | 860 | } else { |
| 861 | 861 | return false; |
@@ -872,38 +872,38 @@ discard block |
||
| 872 | 872 | * @param int $order_id WC order ID |
| 873 | 873 | * @return void |
| 874 | 874 | */ |
| 875 | - public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
| 875 | + public function sensei_woocommerce_complete_order($order_id = 0) { |
|
| 876 | 876 | $order_user = array(); |
| 877 | 877 | // Check for WooCommerce |
| 878 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 878 | + if (Sensei_WC::is_woocommerce_active() && (0 < $order_id)) { |
|
| 879 | 879 | // Get order object |
| 880 | - $order = new WC_Order( $order_id ); |
|
| 881 | - $user = get_user_by( 'id', $order->user_id ); |
|
| 880 | + $order = new WC_Order($order_id); |
|
| 881 | + $user = get_user_by('id', $order->user_id); |
|
| 882 | 882 | $order_user['ID'] = $user->ID; |
| 883 | 883 | $order_user['user_login'] = $user->user_login; |
| 884 | 884 | $order_user['user_email'] = $user->user_email; |
| 885 | 885 | $order_user['user_url'] = $user->user_url; |
| 886 | 886 | // Run through each product ordered |
| 887 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 888 | - foreach( $order->get_items() as $item ) { |
|
| 887 | + if (0 < sizeof($order->get_items())) { |
|
| 888 | + foreach ($order->get_items() as $item) { |
|
| 889 | 889 | $product_type = ''; |
| 890 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 890 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 891 | 891 | $item_id = $item['variation_id']; |
| 892 | 892 | $product_type = 'variation'; |
| 893 | 893 | } else { |
| 894 | 894 | $item_id = $item['product_id']; |
| 895 | 895 | } // End If Statement |
| 896 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 896 | + $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type); |
|
| 897 | 897 | // Get courses that use the WC product |
| 898 | - $courses = $this->post_types->course->get_product_courses( $_product->id ); |
|
| 898 | + $courses = $this->post_types->course->get_product_courses($_product->id); |
|
| 899 | 899 | // Loop and update those courses |
| 900 | - foreach ( $courses as $course_item ) { |
|
| 901 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 900 | + foreach ($courses as $course_item) { |
|
| 901 | + $update_course = $this->woocommerce_course_update($course_item->ID, $order_user); |
|
| 902 | 902 | } // End For Loop |
| 903 | 903 | } // End For Loop |
| 904 | 904 | } // End If Statement |
| 905 | 905 | // Add meta to indicate that payment has been completed successfully |
| 906 | - update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 906 | + update_post_meta($order_id, 'sensei_payment_complete', '1'); |
|
| 907 | 907 | } // End If Statement |
| 908 | 908 | } // End sensei_woocommerce_complete_order() |
| 909 | 909 | |
@@ -914,36 +914,36 @@ discard block |
||
| 914 | 914 | * @param integer $order_id order ID |
| 915 | 915 | * @return void |
| 916 | 916 | */ |
| 917 | - public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
| 917 | + public function sensei_woocommerce_cancel_order($order_id) { |
|
| 918 | 918 | |
| 919 | 919 | // Get order object |
| 920 | - $order = new WC_Order( $order_id ); |
|
| 920 | + $order = new WC_Order($order_id); |
|
| 921 | 921 | |
| 922 | 922 | // Run through each product ordered |
| 923 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 923 | + if (0 < sizeof($order->get_items())) { |
|
| 924 | 924 | |
| 925 | 925 | // Get order user |
| 926 | - $user_id = $order->__get( 'user_id' ); |
|
| 926 | + $user_id = $order->__get('user_id'); |
|
| 927 | 927 | |
| 928 | - foreach( $order->get_items() as $item ) { |
|
| 928 | + foreach ($order->get_items() as $item) { |
|
| 929 | 929 | |
| 930 | 930 | $product_type = ''; |
| 931 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 931 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 932 | 932 | $item_id = $item['variation_id']; |
| 933 | 933 | $product_type = 'variation'; |
| 934 | 934 | } else { |
| 935 | 935 | $item_id = $item['product_id']; |
| 936 | 936 | } // End If Statement |
| 937 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 937 | + $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type); |
|
| 938 | 938 | |
| 939 | 939 | // Get courses that use the WC product |
| 940 | 940 | $courses = array(); |
| 941 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 941 | + $courses = $this->post_types->course->get_product_courses($item_id); |
|
| 942 | 942 | |
| 943 | 943 | // Loop and update those courses |
| 944 | - foreach ($courses as $course_item){ |
|
| 944 | + foreach ($courses as $course_item) { |
|
| 945 | 945 | // Check and Remove course from courses user meta |
| 946 | - $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 946 | + $dataset_changes = Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id); |
|
| 947 | 947 | } // End For Loop |
| 948 | 948 | } // End For Loop |
| 949 | 949 | } // End If Statement |
@@ -957,9 +957,9 @@ discard block |
||
| 957 | 957 | * @param integer $subscription_key Subscription Unique Key |
| 958 | 958 | * @return void |
| 959 | 959 | */ |
| 960 | - public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) { |
|
| 961 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 962 | - self::sensei_woocommerce_cancel_order( $subscription['order_id'] ); |
|
| 960 | + public function sensei_woocommerce_subscription_ended($user_id, $subscription_key) { |
|
| 961 | + $subscription = WC_Subscriptions_Manager::get_users_subscription($user_id, $subscription_key); |
|
| 962 | + self::sensei_woocommerce_cancel_order($subscription['order_id']); |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | /** |
@@ -970,18 +970,18 @@ discard block |
||
| 970 | 970 | * @param integer $subscription_key Subscription Unique Key |
| 971 | 971 | * @return void |
| 972 | 972 | */ |
| 973 | - public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) { |
|
| 974 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 975 | - $order = new WC_Order( $subscription['order_id'] ); |
|
| 976 | - $user = get_user_by( 'id', $order->user_id ); |
|
| 973 | + public function sensei_woocommerce_reactivate_subscription($user_id, $subscription_key) { |
|
| 974 | + $subscription = WC_Subscriptions_Manager::get_users_subscription($user_id, $subscription_key); |
|
| 975 | + $order = new WC_Order($subscription['order_id']); |
|
| 976 | + $user = get_user_by('id', $order->user_id); |
|
| 977 | 977 | $order_user = array(); |
| 978 | 978 | $order_user['ID'] = $user->ID; |
| 979 | 979 | $order_user['user_login'] = $user->user_login; |
| 980 | 980 | $order_user['user_email'] = $user->user_email; |
| 981 | 981 | $order_user['user_url'] = $user->user_url; |
| 982 | - $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] ); |
|
| 983 | - foreach ( $courses as $course_item ){ |
|
| 984 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 982 | + $courses = $this->post_types->course->get_product_courses($subscription['product_id']); |
|
| 983 | + foreach ($courses as $course_item) { |
|
| 984 | + $update_course = $this->woocommerce_course_update($course_item->ID, $order_user); |
|
| 985 | 985 | } // End For Loop |
| 986 | 986 | } // End sensei_woocommerce_reactivate_subscription |
| 987 | 987 | |
@@ -996,30 +996,30 @@ discard block |
||
| 996 | 996 | * @param string $product_type '' or 'variation' |
| 997 | 997 | * @return WC_Product $wc_product_object |
| 998 | 998 | */ |
| 999 | - public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 999 | + public function sensei_get_woocommerce_product_object($wc_product_id = 0, $product_type = '') { |
|
| 1000 | 1000 | |
| 1001 | 1001 | $wc_product_object = false; |
| 1002 | - if ( 0 < intval( $wc_product_id ) ) { |
|
| 1002 | + if (0 < intval($wc_product_id)) { |
|
| 1003 | 1003 | |
| 1004 | 1004 | // Get the product |
| 1005 | - if ( function_exists( 'wc_get_product' ) ) { |
|
| 1005 | + if (function_exists('wc_get_product')) { |
|
| 1006 | 1006 | |
| 1007 | - $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1007 | + $wc_product_object = wc_get_product($wc_product_id); // Post WC 2.3 |
|
| 1008 | 1008 | |
| 1009 | - } elseif ( function_exists( 'get_product' ) ) { |
|
| 1009 | + } elseif (function_exists('get_product')) { |
|
| 1010 | 1010 | |
| 1011 | - $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1011 | + $wc_product_object = get_product($wc_product_id); // Post WC 2.0 |
|
| 1012 | 1012 | |
| 1013 | 1013 | } else { |
| 1014 | 1014 | |
| 1015 | 1015 | // Pre WC 2.0 |
| 1016 | - if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1016 | + if ('variation' == $product_type || 'subscription_variation' == $product_type) { |
|
| 1017 | 1017 | |
| 1018 | - $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1018 | + $wc_product_object = new WC_Product_Variation($wc_product_id); |
|
| 1019 | 1019 | |
| 1020 | 1020 | } else { |
| 1021 | 1021 | |
| 1022 | - $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1022 | + $wc_product_object = new WC_Product($wc_product_id); |
|
| 1023 | 1023 | |
| 1024 | 1024 | } // End If Statement |
| 1025 | 1025 | |
@@ -1037,9 +1037,9 @@ discard block |
||
| 1037 | 1037 | * @access public |
| 1038 | 1038 | * @return void |
| 1039 | 1039 | */ |
| 1040 | - public function load_class ( $class_name = '' ) { |
|
| 1041 | - if ( '' != $class_name && '' != $this->token ) { |
|
| 1042 | - require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
| 1040 | + public function load_class($class_name = '') { |
|
| 1041 | + if ('' != $class_name && '' != $this->token) { |
|
| 1042 | + require_once('class-'.esc_attr($this->token).'-'.esc_attr($class_name).'.php'); |
|
| 1043 | 1043 | } // End If Statement |
| 1044 | 1044 | } // End load_class() |
| 1045 | 1045 | |
@@ -1050,17 +1050,17 @@ discard block |
||
| 1050 | 1050 | * @param integer $order_id order ID |
| 1051 | 1051 | * @return void |
| 1052 | 1052 | */ |
| 1053 | - public function sensei_activate_subscription( $order_id = 0 ) { |
|
| 1054 | - if ( 0 < intval( $order_id ) ) { |
|
| 1055 | - $order = new WC_Order( $order_id ); |
|
| 1053 | + public function sensei_activate_subscription($order_id = 0) { |
|
| 1054 | + if (0 < intval($order_id)) { |
|
| 1055 | + $order = new WC_Order($order_id); |
|
| 1056 | 1056 | $user = get_user_by('id', $order->user_id); |
| 1057 | 1057 | $order_user['ID'] = $user->ID; |
| 1058 | 1058 | $order_user['user_login'] = $user->user_login; |
| 1059 | 1059 | $order_user['user_email'] = $user->user_email; |
| 1060 | 1060 | $order_user['user_url'] = $user->user_url; |
| 1061 | 1061 | // Run through each product ordered |
| 1062 | - if (sizeof($order->get_items())>0) { |
|
| 1063 | - foreach($order->get_items() as $item) { |
|
| 1062 | + if (sizeof($order->get_items()) > 0) { |
|
| 1063 | + foreach ($order->get_items() as $item) { |
|
| 1064 | 1064 | $product_type = ''; |
| 1065 | 1065 | if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
| 1066 | 1066 | $item_id = $item['variation_id']; |
@@ -1068,15 +1068,15 @@ discard block |
||
| 1068 | 1068 | } else { |
| 1069 | 1069 | $item_id = $item['product_id']; |
| 1070 | 1070 | } // End If Statement |
| 1071 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 1071 | + $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type); |
|
| 1072 | 1072 | // Get courses that use the WC product |
| 1073 | 1073 | $courses = array(); |
| 1074 | - if ( $product_type == 'subscription_variation' ) { |
|
| 1075 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 1074 | + if ($product_type == 'subscription_variation') { |
|
| 1075 | + $courses = $this->post_types->course->get_product_courses($item_id); |
|
| 1076 | 1076 | } // End If Statement |
| 1077 | 1077 | // Loop and update those courses |
| 1078 | - foreach ($courses as $course_item){ |
|
| 1079 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 1078 | + foreach ($courses as $course_item) { |
|
| 1079 | + $update_course = $this->woocommerce_course_update($course_item->ID, $order_user); |
|
| 1080 | 1080 | } // End For Loop |
| 1081 | 1081 | } // End For Loop |
| 1082 | 1082 | } // End If Statement |
@@ -1090,12 +1090,12 @@ discard block |
||
| 1090 | 1090 | * @param WC_Order $order |
| 1091 | 1091 | * @return void |
| 1092 | 1092 | */ |
| 1093 | - public function sensei_woocommerce_email_course_details( $order ) { |
|
| 1093 | + public function sensei_woocommerce_email_course_details($order) { |
|
| 1094 | 1094 | global $woocommerce; |
| 1095 | 1095 | |
| 1096 | 1096 | // exit early if not wc-completed or wc-processing |
| 1097 | - if( 'wc-completed' != $order->post_status |
|
| 1098 | - && 'wc-processing' != $order->post_status ) { |
|
| 1097 | + if ('wc-completed' != $order->post_status |
|
| 1098 | + && 'wc-processing' != $order->post_status) { |
|
| 1099 | 1099 | return; |
| 1100 | 1100 | } |
| 1101 | 1101 | |
@@ -1103,14 +1103,14 @@ discard block |
||
| 1103 | 1103 | $order_id = $order->id; |
| 1104 | 1104 | |
| 1105 | 1105 | //If object have items go through them all to find course |
| 1106 | - if ( 0 < sizeof( $order_items ) ) { |
|
| 1106 | + if (0 < sizeof($order_items)) { |
|
| 1107 | 1107 | |
| 1108 | - echo '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1108 | + echo '<h2>'.__('Course details', 'woothemes-sensei').'</h2>'; |
|
| 1109 | 1109 | |
| 1110 | - foreach ( $order_items as $item ) { |
|
| 1110 | + foreach ($order_items as $item) { |
|
| 1111 | 1111 | |
| 1112 | 1112 | $product_type = ''; |
| 1113 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1113 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 1114 | 1114 | // If item has variation_id then its from variation |
| 1115 | 1115 | $item_id = $item['variation_id']; |
| 1116 | 1116 | $product_type = 'variation'; |
@@ -1119,9 +1119,9 @@ discard block |
||
| 1119 | 1119 | $item_id = $item['product_id']; |
| 1120 | 1120 | } // End If Statement |
| 1121 | 1121 | |
| 1122 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1122 | + $user_id = get_post_meta($order_id, '_customer_user', true); |
|
| 1123 | 1123 | |
| 1124 | - if( $user_id ) { |
|
| 1124 | + if ($user_id) { |
|
| 1125 | 1125 | |
| 1126 | 1126 | // Get all courses for product |
| 1127 | 1127 | $args = array( |
@@ -1136,16 +1136,16 @@ discard block |
||
| 1136 | 1136 | 'orderby' => 'menu_order date', |
| 1137 | 1137 | 'order' => 'ASC', |
| 1138 | 1138 | ); |
| 1139 | - $courses = get_posts( $args ); |
|
| 1139 | + $courses = get_posts($args); |
|
| 1140 | 1140 | |
| 1141 | - if( $courses && count( $courses ) > 0 ) { |
|
| 1141 | + if ($courses && count($courses) > 0) { |
|
| 1142 | 1142 | |
| 1143 | - foreach( $courses as $course ) { |
|
| 1143 | + foreach ($courses as $course) { |
|
| 1144 | 1144 | |
| 1145 | 1145 | $title = $course->post_title; |
| 1146 | - $permalink = get_permalink( $course->ID ); |
|
| 1146 | + $permalink = get_permalink($course->ID); |
|
| 1147 | 1147 | |
| 1148 | - echo '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1148 | + echo '<p><strong>'.sprintf(__('View course: %1$s', 'woothemes-sensei'), '</strong><a href="'.esc_url($permalink).'">'.$title.'</a>').'</p>'; |
|
| 1149 | 1149 | } |
| 1150 | 1150 | } |
| 1151 | 1151 | } |
@@ -1161,44 +1161,44 @@ discard block |
||
| 1161 | 1161 | * @param integer $post_id |
| 1162 | 1162 | * @return array |
| 1163 | 1163 | */ |
| 1164 | - public function sensei_count_comments( $comments, $post_id ) { |
|
| 1164 | + public function sensei_count_comments($comments, $post_id) { |
|
| 1165 | 1165 | global $wpdb; |
| 1166 | 1166 | |
| 1167 | 1167 | $post_id = (int) $post_id; |
| 1168 | 1168 | |
| 1169 | 1169 | $count = wp_cache_get("comments-{$post_id}", 'counts'); |
| 1170 | 1170 | |
| 1171 | - if ( false !== $count ) { |
|
| 1171 | + if (false !== $count) { |
|
| 1172 | 1172 | return $count; |
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | - $statuses = array( '' ); // Default to the WP normal comments |
|
| 1176 | - $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
| 1177 | - foreach ( (array) $stati AS $status ) { |
|
| 1178 | - if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
| 1175 | + $statuses = array(''); // Default to the WP normal comments |
|
| 1176 | + $stati = $wpdb->get_results("SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A); |
|
| 1177 | + foreach ((array) $stati AS $status) { |
|
| 1178 | + if ('sensei_' != substr($status['comment_type'], 0, 7)) { |
|
| 1179 | 1179 | $statuses[] = $status['comment_type']; |
| 1180 | 1180 | } |
| 1181 | 1181 | } |
| 1182 | - $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
| 1182 | + $where = "WHERE comment_type IN ('".join("', '", array_unique($statuses))."')"; |
|
| 1183 | 1183 | |
| 1184 | - if ( $post_id > 0 ) |
|
| 1185 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1184 | + if ($post_id > 0) |
|
| 1185 | + $where .= $wpdb->prepare(" AND comment_post_ID = %d", $post_id); |
|
| 1186 | 1186 | |
| 1187 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 1187 | + $count = $wpdb->get_results("SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A); |
|
| 1188 | 1188 | |
| 1189 | 1189 | $total = 0; |
| 1190 | 1190 | $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
| 1191 | - foreach ( (array) $count as $row ) { |
|
| 1191 | + foreach ((array) $count as $row) { |
|
| 1192 | 1192 | // Don't count post-trashed toward totals |
| 1193 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 1193 | + if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved']) |
|
| 1194 | 1194 | $total += $row['num_comments']; |
| 1195 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 1195 | + if (isset($approved[$row['comment_approved']])) |
|
| 1196 | 1196 | $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | $stats['total_comments'] = $total; |
| 1200 | - foreach ( $approved as $key ) { |
|
| 1201 | - if ( empty($stats[$key]) ) |
|
| 1200 | + foreach ($approved as $key) { |
|
| 1201 | + if (empty($stats[$key])) |
|
| 1202 | 1202 | $stats[$key] = 0; |
| 1203 | 1203 | } |
| 1204 | 1204 | |
@@ -1216,15 +1216,15 @@ discard block |
||
| 1216 | 1216 | * @return void |
| 1217 | 1217 | */ |
| 1218 | 1218 | public function init_image_sizes() { |
| 1219 | - $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
| 1220 | - $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
| 1221 | - $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
| 1222 | - $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
| 1223 | - |
|
| 1224 | - add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
| 1225 | - add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
| 1226 | - add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
| 1227 | - add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
| 1219 | + $course_archive_thumbnail = $this->get_image_size('course_archive_image'); |
|
| 1220 | + $course_single_thumbnail = $this->get_image_size('course_single_image'); |
|
| 1221 | + $lesson_archive_thumbnail = $this->get_image_size('lesson_archive_image'); |
|
| 1222 | + $lesson_single_thumbnail = $this->get_image_size('lesson_single_image'); |
|
| 1223 | + |
|
| 1224 | + add_image_size('course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop']); |
|
| 1225 | + add_image_size('course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop']); |
|
| 1226 | + add_image_size('lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop']); |
|
| 1227 | + add_image_size('lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop']); |
|
| 1228 | 1228 | } |
| 1229 | 1229 | |
| 1230 | 1230 | /** |
@@ -1237,37 +1237,37 @@ discard block |
||
| 1237 | 1237 | * @param mixed $image_size |
| 1238 | 1238 | * @return string |
| 1239 | 1239 | */ |
| 1240 | - public function get_image_size( $image_size ) { |
|
| 1240 | + public function get_image_size($image_size) { |
|
| 1241 | 1241 | |
| 1242 | 1242 | // Only return sizes we define in settings |
| 1243 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 1244 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1243 | + if ( ! in_array($image_size, array('course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image'))) |
|
| 1244 | + return apply_filters('sensei_get_image_size_'.$image_size, ''); |
|
| 1245 | 1245 | |
| 1246 | - if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
| 1247 | - $this->settings->settings[ $image_size . '_width' ] = false; |
|
| 1246 | + if ( ! isset($this->settings->settings[$image_size.'_width'])) { |
|
| 1247 | + $this->settings->settings[$image_size.'_width'] = false; |
|
| 1248 | 1248 | } |
| 1249 | - if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
| 1250 | - $this->settings->settings[ $image_size . '_height' ] = false; |
|
| 1249 | + if ( ! isset($this->settings->settings[$image_size.'_height'])) { |
|
| 1250 | + $this->settings->settings[$image_size.'_height'] = false; |
|
| 1251 | 1251 | } |
| 1252 | - if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
| 1253 | - $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
| 1252 | + if ( ! isset($this->settings->settings[$image_size.'_hard_crop'])) { |
|
| 1253 | + $this->settings->settings[$image_size.'_hard_crop'] = false; |
|
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | - $size = array_filter( array( |
|
| 1257 | - 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
| 1258 | - 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
| 1259 | - 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
| 1260 | - ) ); |
|
| 1256 | + $size = array_filter(array( |
|
| 1257 | + 'width' => $this->settings->settings[$image_size.'_width'], |
|
| 1258 | + 'height' => $this->settings->settings[$image_size.'_height'], |
|
| 1259 | + 'crop' => $this->settings->settings[$image_size.'_hard_crop'] |
|
| 1260 | + )); |
|
| 1261 | 1261 | |
| 1262 | - $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
| 1263 | - $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
| 1264 | - $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
| 1262 | + $size['width'] = isset($size['width']) ? $size['width'] : '100'; |
|
| 1263 | + $size['height'] = isset($size['height']) ? $size['height'] : '100'; |
|
| 1264 | + $size['crop'] = isset($size['crop']) ? $size['crop'] : 0; |
|
| 1265 | 1265 | |
| 1266 | - return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
| 1266 | + return apply_filters('sensei_get_image_size_'.$image_size, $size); |
|
| 1267 | 1267 | } |
| 1268 | 1268 | |
| 1269 | - public function body_class( $classes ) { |
|
| 1270 | - if( is_sensei() ) { |
|
| 1269 | + public function body_class($classes) { |
|
| 1270 | + if (is_sensei()) { |
|
| 1271 | 1271 | $classes[] = 'sensei'; |
| 1272 | 1272 | } |
| 1273 | 1273 | return $classes; |
@@ -1280,9 +1280,9 @@ discard block |
||
| 1280 | 1280 | * @since 1.7.0 |
| 1281 | 1281 | */ |
| 1282 | 1282 | public function jetpack_latex_support() { |
| 1283 | - if ( function_exists( 'latex_markup') ) { |
|
| 1284 | - add_filter( 'sensei_question_title', 'latex_markup' ); |
|
| 1285 | - add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
| 1283 | + if (function_exists('latex_markup')) { |
|
| 1284 | + add_filter('sensei_question_title', 'latex_markup'); |
|
| 1285 | + add_filter('sensei_answer_text', 'latex_markup'); |
|
| 1286 | 1286 | } |
| 1287 | 1287 | } |
| 1288 | 1288 | |
@@ -1294,21 +1294,21 @@ discard block |
||
| 1294 | 1294 | * |
| 1295 | 1295 | * @since 1.8.0 |
| 1296 | 1296 | */ |
| 1297 | - public function load_modules_class(){ |
|
| 1297 | + public function load_modules_class() { |
|
| 1298 | 1298 | global $sensei_modules; |
| 1299 | 1299 | |
| 1300 | - if( !class_exists( 'Sensei_Modules' ) |
|
| 1301 | - && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
| 1300 | + if ( ! class_exists('Sensei_Modules') |
|
| 1301 | + && 'Sensei_Modules' != get_class($sensei_modules)) { |
|
| 1302 | 1302 | |
| 1303 | 1303 | //Load the modules class |
| 1304 | - require_once( 'class-sensei-modules.php'); |
|
| 1305 | - Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
| 1304 | + require_once('class-sensei-modules.php'); |
|
| 1305 | + Sensei()->modules = new Sensei_Core_Modules($this->file); |
|
| 1306 | 1306 | |
| 1307 | - }else{ |
|
| 1307 | + } else { |
|
| 1308 | 1308 | // fallback for people still using the modules extension. |
| 1309 | 1309 | global $sensei_modules; |
| 1310 | 1310 | Sensei()->modules = $sensei_modules; |
| 1311 | - add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
| 1311 | + add_action('admin_notices', array($this, 'disable_sensei_modules_extension'), 30); |
|
| 1312 | 1312 | } |
| 1313 | 1313 | } |
| 1314 | 1314 | |
@@ -1317,12 +1317,12 @@ discard block |
||
| 1317 | 1317 | * |
| 1318 | 1318 | * @since 1.8.0 |
| 1319 | 1319 | */ |
| 1320 | - public function disable_sensei_modules_extension(){ ?> |
|
| 1320 | + public function disable_sensei_modules_extension() { ?> |
|
| 1321 | 1321 | <div class="notice updated fade"> |
| 1322 | 1322 | <p> |
| 1323 | 1323 | <?php |
| 1324 | 1324 | $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
| 1325 | - $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
| 1325 | + $plugin_link_element = '<a href="'.$plugin_manage_url.'" >plugins page</a> '; |
|
| 1326 | 1326 | ?> |
| 1327 | 1327 | <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension. |
| 1328 | 1328 | Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules). |
@@ -1340,18 +1340,18 @@ discard block |
||
| 1340 | 1340 | * |
| 1341 | 1341 | * @since 1.9.0 |
| 1342 | 1342 | */ |
| 1343 | - public function flush_rewrite_rules(){ |
|
| 1343 | + public function flush_rewrite_rules() { |
|
| 1344 | 1344 | |
| 1345 | 1345 | // ensures that the rewrite rules are flushed on the second |
| 1346 | 1346 | // attempt. This ensure that the settings for any other process |
| 1347 | 1347 | // have been completed and saved to the database before we refresh the |
| 1348 | 1348 | // rewrite rules. |
| 1349 | - $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1350 | - if( '1' == $option ) { |
|
| 1349 | + $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1350 | + if ('1' == $option) { |
|
| 1351 | 1351 | |
| 1352 | 1352 | update_option('sensei_flush_rewrite_rules', '2'); |
| 1353 | 1353 | |
| 1354 | - }elseif( '2' == $option ) { |
|
| 1354 | + }elseif ('2' == $option) { |
|
| 1355 | 1355 | |
| 1356 | 1356 | flush_rewrite_rules(); |
| 1357 | 1357 | update_option('sensei_flush_rewrite_rules', '0'); |
@@ -1366,7 +1366,7 @@ discard block |
||
| 1366 | 1366 | * |
| 1367 | 1367 | * @since 1.9.0 |
| 1368 | 1368 | */ |
| 1369 | - public function initiate_rewrite_rules_flush(){ |
|
| 1369 | + public function initiate_rewrite_rules_flush() { |
|
| 1370 | 1370 | |
| 1371 | 1371 | update_option('sensei_flush_rewrite_rules', '1'); |
| 1372 | 1372 | |
@@ -1379,4 +1379,4 @@ discard block |
||
| 1379 | 1379 | * for backward compatibility |
| 1380 | 1380 | * @since 1.9.0 |
| 1381 | 1381 | */ |
| 1382 | -class Woothemes_Sensei extends Sensei_Main{ } |
|
| 1382 | +class Woothemes_Sensei extends Sensei_Main { } |
|
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 3 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 4 | 4 | |
| 5 | -if ( ! class_exists( 'WooThemes_Sensei_Email_Teacher_Completed_Course' ) ) : |
|
| 5 | +if ( ! class_exists('WooThemes_Sensei_Email_Teacher_Completed_Course')) : |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * Teacher Completed Course |
@@ -31,8 +31,8 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | function __construct() { |
| 33 | 33 | $this->template = 'teacher-completed-course'; |
| 34 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] Your student has completed a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
| 35 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'Your student has completed a course', 'woothemes-sensei' ), $this->template ); |
|
| 34 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] Your student has completed a course', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
| 35 | + $this->heading = apply_filters('sensei_email_heading', __('Your student has completed a course', 'woothemes-sensei'), $this->template); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -41,24 +41,24 @@ discard block |
||
| 41 | 41 | * @access public |
| 42 | 42 | * @return void |
| 43 | 43 | */ |
| 44 | - function trigger( $learner_id = 0, $course_id = 0 ) { |
|
| 44 | + function trigger($learner_id = 0, $course_id = 0) { |
|
| 45 | 45 | global $sensei_email_data; |
| 46 | 46 | |
| 47 | 47 | // Get learner user object |
| 48 | - $this->learner = new WP_User( $learner_id ); |
|
| 48 | + $this->learner = new WP_User($learner_id); |
|
| 49 | 49 | |
| 50 | 50 | // Get teacher ID and user object |
| 51 | - $teacher_id = get_post_field( 'post_author', $course_id, 'raw' ); |
|
| 52 | - $this->teacher = new WP_User( $teacher_id ); |
|
| 51 | + $teacher_id = get_post_field('post_author', $course_id, 'raw'); |
|
| 52 | + $this->teacher = new WP_User($teacher_id); |
|
| 53 | 53 | |
| 54 | 54 | // Get passed status |
| 55 | - $passed = __( 'passed', 'woothemes-sensei' ); |
|
| 56 | - if( ! Sensei_Utils::sensei_user_passed_course( $course_id, $learner_id ) ) { |
|
| 57 | - $passed = __( 'failed', 'woothemes-sensei' ); |
|
| 55 | + $passed = __('passed', 'woothemes-sensei'); |
|
| 56 | + if ( ! Sensei_Utils::sensei_user_passed_course($course_id, $learner_id)) { |
|
| 57 | + $passed = __('failed', 'woothemes-sensei'); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | // Construct data array |
| 61 | - $sensei_email_data = apply_filters( 'sensei_email_data', array( |
|
| 61 | + $sensei_email_data = apply_filters('sensei_email_data', array( |
|
| 62 | 62 | 'template' => $this->template, |
| 63 | 63 | 'heading' => $this->heading, |
| 64 | 64 | 'teacher_id' => $teacher_id, |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | 'learner_name' => $this->learner->display_name, |
| 67 | 67 | 'course_id' => $course_id, |
| 68 | 68 | 'passed' => $passed, |
| 69 | - ), $this->template ); |
|
| 69 | + ), $this->template); |
|
| 70 | 70 | |
| 71 | 71 | // Set recipient (learner) |
| 72 | - $this->recipient = stripslashes( $this->teacher->user_email ); |
|
| 72 | + $this->recipient = stripslashes($this->teacher->user_email); |
|
| 73 | 73 | |
| 74 | 74 | // Send mail |
| 75 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
| 75 | + Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 3 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 4 | 4 | |
| 5 | -if ( ! class_exists( 'WooThemes_Sensei_Email_Learner_Completed_Course' ) ) : |
|
| 5 | +if ( ! class_exists('WooThemes_Sensei_Email_Learner_Completed_Course')) : |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * Learner Completed Course |
@@ -30,8 +30,8 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | function __construct() { |
| 32 | 32 | $this->template = 'learner-completed-course'; |
| 33 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have completed a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
| 34 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'You have completed a course', 'woothemes-sensei' ), $this->template ); |
|
| 33 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] You have completed a course', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
| 34 | + $this->heading = apply_filters('sensei_email_heading', __('You have completed a course', 'woothemes-sensei'), $this->template); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -40,32 +40,32 @@ discard block |
||
| 40 | 40 | * @access public |
| 41 | 41 | * @return void |
| 42 | 42 | */ |
| 43 | - function trigger( $user_id = 0, $course_id = 0 ) { |
|
| 43 | + function trigger($user_id = 0, $course_id = 0) { |
|
| 44 | 44 | global $sensei_email_data; |
| 45 | 45 | |
| 46 | 46 | // Get learner user object |
| 47 | - $this->user = new WP_User( $user_id ); |
|
| 47 | + $this->user = new WP_User($user_id); |
|
| 48 | 48 | |
| 49 | 49 | // Get passed status |
| 50 | - $passed = __( 'passed', 'woothemes-sensei' ); |
|
| 51 | - if( ! Sensei_Utils::sensei_user_passed_course( $course_id, $user_id ) ) { |
|
| 52 | - $passed = __( 'failed', 'woothemes-sensei' ); |
|
| 50 | + $passed = __('passed', 'woothemes-sensei'); |
|
| 51 | + if ( ! Sensei_Utils::sensei_user_passed_course($course_id, $user_id)) { |
|
| 52 | + $passed = __('failed', 'woothemes-sensei'); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // Construct data array |
| 56 | - $sensei_email_data = apply_filters( 'sensei_email_data', array( |
|
| 56 | + $sensei_email_data = apply_filters('sensei_email_data', array( |
|
| 57 | 57 | 'template' => $this->template, |
| 58 | 58 | 'heading' => $this->heading, |
| 59 | 59 | 'user_id' => $user_id, |
| 60 | 60 | 'course_id' => $course_id, |
| 61 | 61 | 'passed' => $passed, |
| 62 | - ), $this->template ); |
|
| 62 | + ), $this->template); |
|
| 63 | 63 | |
| 64 | 64 | // Set recipient (learner) |
| 65 | - $this->recipient = stripslashes( $this->user->user_email ); |
|
| 65 | + $this->recipient = stripslashes($this->user->user_email); |
|
| 66 | 66 | |
| 67 | 67 | // Send mail |
| 68 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
| 68 | + Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); |
|
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | |
@@ -3,11 +3,11 @@ discard block |
||
| 3 | 3 | /** |
| 4 | 4 | * Queue updates for the WooUpdater |
| 5 | 5 | */ |
| 6 | -if ( ! function_exists( 'woothemes_queue_update' ) ) { |
|
| 7 | - function woothemes_queue_update( $file, $file_id, $product_id ) { |
|
| 6 | +if ( ! function_exists('woothemes_queue_update')) { |
|
| 7 | + function woothemes_queue_update($file, $file_id, $product_id) { |
|
| 8 | 8 | global $woothemes_queued_updates; |
| 9 | 9 | |
| 10 | - if ( ! isset( $woothemes_queued_updates ) ) |
|
| 10 | + if ( ! isset($woothemes_queued_updates)) |
|
| 11 | 11 | $woothemes_queued_updates = array(); |
| 12 | 12 | |
| 13 | 13 | $plugin = new stdClass(); |
@@ -23,56 +23,56 @@ discard block |
||
| 23 | 23 | * Load installer for the WooThemes Updater. |
| 24 | 24 | * @return $api Object |
| 25 | 25 | */ |
| 26 | -if ( ! class_exists( 'WooThemes_Updater' ) && ! function_exists( 'woothemes_updater_install' ) ) { |
|
| 27 | - function woothemes_updater_install( $api, $action, $args ) { |
|
| 26 | +if ( ! class_exists('WooThemes_Updater') && ! function_exists('woothemes_updater_install')) { |
|
| 27 | + function woothemes_updater_install($api, $action, $args) { |
|
| 28 | 28 | $download_url = 'http://woodojo.s3.amazonaws.com/downloads/woothemes-updater/woothemes-updater.zip'; |
| 29 | 29 | |
| 30 | - if ( 'plugin_information' != $action || |
|
| 30 | + if ('plugin_information' != $action || |
|
| 31 | 31 | false !== $api || |
| 32 | - ! isset( $args->slug ) || |
|
| 32 | + ! isset($args->slug) || |
|
| 33 | 33 | 'woothemes-updater' != $args->slug |
| 34 | 34 | ) return $api; |
| 35 | 35 | |
| 36 | 36 | $api = new stdClass(); |
| 37 | 37 | $api->name = 'WooThemes Updater'; |
| 38 | 38 | $api->version = ''; |
| 39 | - $api->download_link = esc_url( $download_url ); |
|
| 39 | + $api->download_link = esc_url($download_url); |
|
| 40 | 40 | return $api; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - add_filter( 'plugins_api', 'woothemes_updater_install', 10, 3 ); |
|
| 43 | + add_filter('plugins_api', 'woothemes_updater_install', 10, 3); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * WooUpdater Installation Prompts |
| 48 | 48 | */ |
| 49 | -if ( ! class_exists( 'WooThemes_Updater' ) && ! function_exists( 'woothemes_updater_notice' ) ) { |
|
| 49 | +if ( ! class_exists('WooThemes_Updater') && ! function_exists('woothemes_updater_notice')) { |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * Display a notice if the "WooThemes Updater" plugin hasn't been installed. |
| 53 | 53 | * @return void |
| 54 | 54 | */ |
| 55 | 55 | function woothemes_updater_notice() { |
| 56 | - $active_plugins = apply_filters( 'active_plugins', get_option('active_plugins' ) ); |
|
| 57 | - if ( in_array( 'woothemes-updater/woothemes-updater.php', $active_plugins ) ) return; |
|
| 56 | + $active_plugins = apply_filters('active_plugins', get_option('active_plugins')); |
|
| 57 | + if (in_array('woothemes-updater/woothemes-updater.php', $active_plugins)) return; |
|
| 58 | 58 | |
| 59 | 59 | $slug = 'woothemes-updater'; |
| 60 | - $install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug ); |
|
| 61 | - $activate_url = 'plugins.php?action=activate&plugin=' . urlencode( 'woothemes-updater/woothemes-updater.php' ) . '&plugin_status=all&paged=1&s&_wpnonce=' . urlencode( wp_create_nonce( 'activate-plugin_woothemes-updater/woothemes-updater.php' ) ); |
|
| 60 | + $install_url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin='.$slug), 'install-plugin_'.$slug); |
|
| 61 | + $activate_url = 'plugins.php?action=activate&plugin='.urlencode('woothemes-updater/woothemes-updater.php').'&plugin_status=all&paged=1&s&_wpnonce='.urlencode(wp_create_nonce('activate-plugin_woothemes-updater/woothemes-updater.php')); |
|
| 62 | 62 | |
| 63 | - $message = '<a href="' . esc_url( $install_url ) . '">Install the WooThemes Updater plugin</a> to get updates for your WooThemes plugins.'; |
|
| 63 | + $message = '<a href="'.esc_url($install_url).'">Install the WooThemes Updater plugin</a> to get updates for your WooThemes plugins.'; |
|
| 64 | 64 | $is_downloaded = false; |
| 65 | - $plugins = array_keys( get_plugins() ); |
|
| 66 | - foreach ( $plugins as $plugin ) { |
|
| 67 | - if ( strpos( $plugin, 'woothemes-updater.php' ) !== false ) { |
|
| 65 | + $plugins = array_keys(get_plugins()); |
|
| 66 | + foreach ($plugins as $plugin) { |
|
| 67 | + if (strpos($plugin, 'woothemes-updater.php') !== false) { |
|
| 68 | 68 | $is_downloaded = true; |
| 69 | - $message = '<a href="' . esc_url( admin_url( $activate_url ) ) . '">Activate the WooThemes Updater plugin</a> to get updates for your WooThemes plugins.'; |
|
| 69 | + $message = '<a href="'.esc_url(admin_url($activate_url)).'">Activate the WooThemes Updater plugin</a> to get updates for your WooThemes plugins.'; |
|
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | - echo '<div class="updated fade"><p>' . $message . '</p></div>' . "\n"; |
|
| 72 | + echo '<div class="updated fade"><p>'.$message.'</p></div>'."\n"; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - add_action( 'admin_notices', 'woothemes_updater_notice' ); |
|
| 75 | + add_action('admin_notices', 'woothemes_updater_notice'); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | * @param $version Version to check against |
| 82 | 82 | * @return @boolean |
| 83 | 83 | */ |
| 84 | -if( ! function_exists( 'sensei_check_woocommerce_version' ) ) { |
|
| 85 | - function sensei_check_woocommerce_version( $version = '2.1' ) { |
|
| 86 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 84 | +if ( ! function_exists('sensei_check_woocommerce_version')) { |
|
| 85 | + function sensei_check_woocommerce_version($version = '2.1') { |
|
| 86 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 87 | 87 | global $woocommerce; |
| 88 | - if( version_compare( $woocommerce->version, $version, ">=" ) ) { |
|
| 88 | + if (version_compare($woocommerce->version, $version, ">=")) { |
|
| 89 | 89 | return true; |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | if( isset( $post->ID ) ) { |
| 119 | 119 | |
| 120 | - $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 120 | + $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 121 | 121 | |
| 122 | 122 | if( $question_type ) { |
| 123 | 123 | $type = $this->question_types[ $question_type ]; |
@@ -237,15 +237,15 @@ discard block |
||
| 237 | 237 | public function save_question( $post_id = 0 ) { |
| 238 | 238 | |
| 239 | 239 | if( ! isset( $_POST['post_type'] |
| 240 | - ) || 'question' != $_POST['post_type'] ) { |
|
| 241 | - return; |
|
| 242 | - } |
|
| 240 | + ) || 'question' != $_POST['post_type'] ) { |
|
| 241 | + return; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | 244 | |
| 245 | 245 | |
| 246 | - //setup the data for saving |
|
| 246 | + //setup the data for saving |
|
| 247 | 247 | $data = $_POST ; |
| 248 | - $data['quiz_id'] = 0; |
|
| 248 | + $data['quiz_id'] = 0; |
|
| 249 | 249 | $data['question_id'] = $post_id; |
| 250 | 250 | |
| 251 | 251 | if ( ! wp_is_post_revision( $post_id ) ){ |
@@ -339,34 +339,34 @@ discard block |
||
| 339 | 339 | return $request; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - /** |
|
| 343 | - * Get the type of question by id |
|
| 344 | - * |
|
| 345 | - * This function uses the post terms to determine which question type |
|
| 346 | - * the passed question id belongs to. |
|
| 347 | - * |
|
| 348 | - * @since 1.7.4 |
|
| 349 | - * |
|
| 350 | - * @param int $question_id |
|
| 351 | - * |
|
| 352 | - * @return string $question_type | bool |
|
| 353 | - */ |
|
| 354 | - public function get_question_type( $question_id ){ |
|
| 355 | - |
|
| 356 | - if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 357 | - || 'question' != get_post_type( $question_id ) ){ |
|
| 358 | - return false; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - $question_type = 'multiple-choice'; |
|
| 362 | - $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
| 363 | - foreach( $question_types as $type ) { |
|
| 364 | - $question_type = $type->slug; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - return $question_type; |
|
| 368 | - |
|
| 369 | - }// end get_question_type |
|
| 342 | + /** |
|
| 343 | + * Get the type of question by id |
|
| 344 | + * |
|
| 345 | + * This function uses the post terms to determine which question type |
|
| 346 | + * the passed question id belongs to. |
|
| 347 | + * |
|
| 348 | + * @since 1.7.4 |
|
| 349 | + * |
|
| 350 | + * @param int $question_id |
|
| 351 | + * |
|
| 352 | + * @return string $question_type | bool |
|
| 353 | + */ |
|
| 354 | + public function get_question_type( $question_id ){ |
|
| 355 | + |
|
| 356 | + if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 357 | + || 'question' != get_post_type( $question_id ) ){ |
|
| 358 | + return false; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + $question_type = 'multiple-choice'; |
|
| 362 | + $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
| 363 | + foreach( $question_types as $type ) { |
|
| 364 | + $question_type = $type->slug; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + return $question_type; |
|
| 368 | + |
|
| 369 | + }// end get_question_type |
|
| 370 | 370 | |
| 371 | 371 | /** |
| 372 | 372 | * Given a question ID, return the grade that can be achieved. |
@@ -398,317 +398,317 @@ discard block |
||
| 398 | 398 | } // end get_question_grade |
| 399 | 399 | |
| 400 | 400 | |
| 401 | - /** |
|
| 402 | - * This function simply loads the question type template |
|
| 403 | - * |
|
| 404 | - * @since 1.9.0 |
|
| 405 | - * @param $question_type |
|
| 406 | - */ |
|
| 407 | - public static function load_question_template( $question_type ){ |
|
| 408 | - |
|
| 409 | - Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Echo the sensei question title. |
|
| 414 | - * |
|
| 415 | - * @uses WooThemes_Sensei_Question::get_the_question_title |
|
| 416 | - * |
|
| 417 | - * @since 1.9.0 |
|
| 418 | - * @param $question_id |
|
| 419 | - */ |
|
| 420 | - public static function the_question_title( $question_id ){ |
|
| 421 | - |
|
| 422 | - echo self::get_the_question_title( $question_id ); |
|
| 423 | - |
|
| 424 | - }// end the_question_title |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Generate the question title with it's grade. |
|
| 428 | - * |
|
| 429 | - * @since 1.9.0 |
|
| 430 | - * |
|
| 431 | - * @param $question_id |
|
| 432 | - * @return string |
|
| 433 | - */ |
|
| 434 | - public static function get_the_question_title( $question_id ){ |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Filter the sensei question title |
|
| 438 | - * |
|
| 439 | - * @since 1.3.0 |
|
| 440 | - * @param $question_title |
|
| 441 | - */ |
|
| 442 | - $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * hook document in class-woothemes-sensei-message.php the_title() |
|
| 446 | - */ |
|
| 447 | - $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
| 448 | - |
|
| 449 | - $title_html = '<span class="question question-title">'; |
|
| 450 | - $title_html .= $title; |
|
| 451 | - $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
|
| 452 | - $title_html .='</span>'; |
|
| 453 | - |
|
| 454 | - return $title_html; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Tech the question description |
|
| 459 | - * |
|
| 460 | - * @param $question_id |
|
| 461 | - * @return string |
|
| 462 | - */ |
|
| 463 | - public static function get_the_question_description( $question_id ){ |
|
| 464 | - |
|
| 465 | - $question = get_post( $question_id ); |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Already documented within WordPress Core |
|
| 469 | - */ |
|
| 470 | - return apply_filters( 'the_content', $question->post_content ); |
|
| 471 | - |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * Output the question description |
|
| 476 | - * |
|
| 477 | - * @since 1.9.0 |
|
| 478 | - * @param $question_id |
|
| 479 | - */ |
|
| 480 | - public static function the_question_description( $question_id ){ |
|
| 481 | - |
|
| 482 | - echo self::get_the_question_description( $question_id ); |
|
| 483 | - |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Get the questions media markup |
|
| 488 | - * |
|
| 489 | - * @since 1.9.0 |
|
| 490 | - * @param $question_id |
|
| 491 | - * @return string |
|
| 492 | - */ |
|
| 493 | - public static function get_the_question_media( $question_id ){ |
|
| 494 | - |
|
| 495 | - $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
| 496 | - $question_media_link = ''; |
|
| 497 | - if( 0 < intval( $question_media ) ) { |
|
| 498 | - $mimetype = get_post_mime_type( $question_media ); |
|
| 499 | - if( $mimetype ) { |
|
| 500 | - $mimetype_array = explode( '/', $mimetype); |
|
| 501 | - if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
| 502 | - $question_media_type = $mimetype_array[0]; |
|
| 503 | - $question_media_url = wp_get_attachment_url( $question_media ); |
|
| 504 | - $attachment = get_post( $question_media ); |
|
| 505 | - $question_media_title = $attachment->post_title; |
|
| 506 | - $question_media_description = $attachment->post_content; |
|
| 507 | - switch( $question_media_type ) { |
|
| 508 | - case 'image': |
|
| 509 | - $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
| 510 | - $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
| 511 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
| 512 | - break; |
|
| 513 | - |
|
| 514 | - case 'audio': |
|
| 515 | - $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
| 516 | - break; |
|
| 517 | - |
|
| 518 | - case 'video': |
|
| 519 | - $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
| 520 | - break; |
|
| 521 | - |
|
| 522 | - default: |
|
| 523 | - $question_media_filename = basename( $question_media_url ); |
|
| 524 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
| 525 | - break; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - $output = ''; |
|
| 532 | - if( $question_media_link ) { |
|
| 533 | - |
|
| 534 | - $output .= '<div class="question_media_display">'; |
|
| 535 | - $output .= $question_media_link; |
|
| 536 | - $output .= '<dl>'; |
|
| 537 | - |
|
| 538 | - if( $question_media_title ) { |
|
| 539 | - |
|
| 540 | - $output .= '<dt>'. $question_media_title. '</dt>'; |
|
| 541 | - |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - if( $question_media_description ) { |
|
| 545 | - |
|
| 546 | - $output .= '<dd>' . $question_media_description . '</dd>'; |
|
| 547 | - |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - $output .= '</dl>'; |
|
| 551 | - $output .= '</div>'; |
|
| 401 | + /** |
|
| 402 | + * This function simply loads the question type template |
|
| 403 | + * |
|
| 404 | + * @since 1.9.0 |
|
| 405 | + * @param $question_type |
|
| 406 | + */ |
|
| 407 | + public static function load_question_template( $question_type ){ |
|
| 408 | + |
|
| 409 | + Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Echo the sensei question title. |
|
| 414 | + * |
|
| 415 | + * @uses WooThemes_Sensei_Question::get_the_question_title |
|
| 416 | + * |
|
| 417 | + * @since 1.9.0 |
|
| 418 | + * @param $question_id |
|
| 419 | + */ |
|
| 420 | + public static function the_question_title( $question_id ){ |
|
| 421 | + |
|
| 422 | + echo self::get_the_question_title( $question_id ); |
|
| 423 | + |
|
| 424 | + }// end the_question_title |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Generate the question title with it's grade. |
|
| 428 | + * |
|
| 429 | + * @since 1.9.0 |
|
| 430 | + * |
|
| 431 | + * @param $question_id |
|
| 432 | + * @return string |
|
| 433 | + */ |
|
| 434 | + public static function get_the_question_title( $question_id ){ |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Filter the sensei question title |
|
| 438 | + * |
|
| 439 | + * @since 1.3.0 |
|
| 440 | + * @param $question_title |
|
| 441 | + */ |
|
| 442 | + $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * hook document in class-woothemes-sensei-message.php the_title() |
|
| 446 | + */ |
|
| 447 | + $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
| 448 | + |
|
| 449 | + $title_html = '<span class="question question-title">'; |
|
| 450 | + $title_html .= $title; |
|
| 451 | + $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
|
| 452 | + $title_html .='</span>'; |
|
| 453 | + |
|
| 454 | + return $title_html; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Tech the question description |
|
| 459 | + * |
|
| 460 | + * @param $question_id |
|
| 461 | + * @return string |
|
| 462 | + */ |
|
| 463 | + public static function get_the_question_description( $question_id ){ |
|
| 464 | + |
|
| 465 | + $question = get_post( $question_id ); |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Already documented within WordPress Core |
|
| 469 | + */ |
|
| 470 | + return apply_filters( 'the_content', $question->post_content ); |
|
| 471 | + |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * Output the question description |
|
| 476 | + * |
|
| 477 | + * @since 1.9.0 |
|
| 478 | + * @param $question_id |
|
| 479 | + */ |
|
| 480 | + public static function the_question_description( $question_id ){ |
|
| 481 | + |
|
| 482 | + echo self::get_the_question_description( $question_id ); |
|
| 483 | + |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Get the questions media markup |
|
| 488 | + * |
|
| 489 | + * @since 1.9.0 |
|
| 490 | + * @param $question_id |
|
| 491 | + * @return string |
|
| 492 | + */ |
|
| 493 | + public static function get_the_question_media( $question_id ){ |
|
| 494 | + |
|
| 495 | + $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
| 496 | + $question_media_link = ''; |
|
| 497 | + if( 0 < intval( $question_media ) ) { |
|
| 498 | + $mimetype = get_post_mime_type( $question_media ); |
|
| 499 | + if( $mimetype ) { |
|
| 500 | + $mimetype_array = explode( '/', $mimetype); |
|
| 501 | + if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
| 502 | + $question_media_type = $mimetype_array[0]; |
|
| 503 | + $question_media_url = wp_get_attachment_url( $question_media ); |
|
| 504 | + $attachment = get_post( $question_media ); |
|
| 505 | + $question_media_title = $attachment->post_title; |
|
| 506 | + $question_media_description = $attachment->post_content; |
|
| 507 | + switch( $question_media_type ) { |
|
| 508 | + case 'image': |
|
| 509 | + $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
| 510 | + $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
| 511 | + $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
| 512 | + break; |
|
| 513 | + |
|
| 514 | + case 'audio': |
|
| 515 | + $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
| 516 | + break; |
|
| 517 | + |
|
| 518 | + case 'video': |
|
| 519 | + $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
| 520 | + break; |
|
| 521 | + |
|
| 522 | + default: |
|
| 523 | + $question_media_filename = basename( $question_media_url ); |
|
| 524 | + $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
| 525 | + break; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + $output = ''; |
|
| 532 | + if( $question_media_link ) { |
|
| 552 | 533 | |
| 534 | + $output .= '<div class="question_media_display">'; |
|
| 535 | + $output .= $question_media_link; |
|
| 536 | + $output .= '<dl>'; |
|
| 553 | 537 | |
| 554 | - } |
|
| 555 | - |
|
| 556 | - return $output; |
|
| 557 | - |
|
| 558 | - } // end get_the_question_media |
|
| 559 | - |
|
| 538 | + if( $question_media_title ) { |
|
| 560 | 539 | |
| 561 | - /** |
|
| 562 | - * Output the question media |
|
| 563 | - * |
|
| 564 | - * @since 1.9.0 |
|
| 565 | - * @param string $question_id |
|
| 566 | - */ |
|
| 567 | - public static function the_question_media( $question_id ){ |
|
| 540 | + $output .= '<dt>'. $question_media_title. '</dt>'; |
|
| 568 | 541 | |
| 569 | - echo self::get_the_question_media( $question_id ); |
|
| 542 | + } |
|
| 570 | 543 | |
| 571 | - } |
|
| 544 | + if( $question_media_description ) { |
|
| 572 | 545 | |
| 573 | - /** |
|
| 574 | - * Output a special field for the question needed for question submission. |
|
| 575 | - * |
|
| 576 | - * @since 1.9.0 |
|
| 577 | - * |
|
| 578 | - * @param $question_id |
|
| 579 | - */ |
|
| 580 | - public static function the_question_hidden_fields( $question_id ){ |
|
| 581 | - ?> |
|
| 546 | + $output .= '<dd>' . $question_media_description . '</dd>'; |
|
| 547 | + |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + $output .= '</dl>'; |
|
| 551 | + $output .= '</div>'; |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + return $output; |
|
| 557 | + |
|
| 558 | + } // end get_the_question_media |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Output the question media |
|
| 563 | + * |
|
| 564 | + * @since 1.9.0 |
|
| 565 | + * @param string $question_id |
|
| 566 | + */ |
|
| 567 | + public static function the_question_media( $question_id ){ |
|
| 568 | + |
|
| 569 | + echo self::get_the_question_media( $question_id ); |
|
| 570 | + |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Output a special field for the question needed for question submission. |
|
| 575 | + * |
|
| 576 | + * @since 1.9.0 |
|
| 577 | + * |
|
| 578 | + * @param $question_id |
|
| 579 | + */ |
|
| 580 | + public static function the_question_hidden_fields( $question_id ){ |
|
| 581 | + ?> |
|
| 582 | 582 | |
| 583 | 583 | <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" /> |
| 584 | 584 | <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" /> |
| 585 | 585 | |
| 586 | 586 | <?php |
| 587 | - } |
|
| 587 | + } |
|
| 588 | 588 | |
| 589 | - /** |
|
| 590 | - * This function can only be run withing the single quiz question loop |
|
| 591 | - * |
|
| 592 | - * @since 1.9.0 |
|
| 593 | - * @param $question_id |
|
| 594 | - */ |
|
| 595 | - public static function answer_feedback_notes( $question_id ){ |
|
| 589 | + /** |
|
| 590 | + * This function can only be run withing the single quiz question loop |
|
| 591 | + * |
|
| 592 | + * @since 1.9.0 |
|
| 593 | + * @param $question_id |
|
| 594 | + */ |
|
| 595 | + public static function answer_feedback_notes( $question_id ){ |
|
| 596 | 596 | |
| 597 | - //IDS |
|
| 598 | - $quiz_id = get_the_ID(); |
|
| 599 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 597 | + //IDS |
|
| 598 | + $quiz_id = get_the_ID(); |
|
| 599 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 600 | 600 | |
| 601 | - // Data to check before showing feedback |
|
| 602 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
| 603 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 604 | - $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
| 605 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 606 | - $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
| 607 | - $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 601 | + // Data to check before showing feedback |
|
| 602 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
| 603 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 604 | + $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
| 605 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 606 | + $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
| 607 | + $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 608 | 608 | |
| 609 | - if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
| 610 | - || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
| 611 | - || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
| 609 | + if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
| 610 | + || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
| 611 | + || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
| 612 | 612 | |
| 613 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
| 613 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
| 614 | 614 | |
| 615 | - if( $answer_notes ) { ?> |
|
| 615 | + if( $answer_notes ) { ?> |
|
| 616 | 616 | |
| 617 | 617 | <div class="sensei-message info info-special answer-feedback"> |
| 618 | 618 | |
| 619 | 619 | <?php |
| 620 | 620 | |
| 621 | - /** |
|
| 622 | - * Filter the answer feedback |
|
| 623 | - * Since 1.9.0 |
|
| 624 | - * |
|
| 625 | - * @param string $answer_notes |
|
| 626 | - * @param string $question_id |
|
| 627 | - * @param string $lesson_id |
|
| 628 | - */ |
|
| 629 | - echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
| 621 | + /** |
|
| 622 | + * Filter the answer feedback |
|
| 623 | + * Since 1.9.0 |
|
| 624 | + * |
|
| 625 | + * @param string $answer_notes |
|
| 626 | + * @param string $question_id |
|
| 627 | + * @param string $lesson_id |
|
| 628 | + */ |
|
| 629 | + echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
| 630 | 630 | |
| 631 | - ?> |
|
| 631 | + ?> |
|
| 632 | 632 | |
| 633 | 633 | </div> |
| 634 | 634 | |
| 635 | 635 | <?php } |
| 636 | 636 | |
| 637 | - }// end if we can show answer feedback |
|
| 637 | + }// end if we can show answer feedback |
|
| 638 | 638 | |
| 639 | - }// end answer_feedback_notes |
|
| 639 | + }// end answer_feedback_notes |
|
| 640 | 640 | |
| 641 | - /** |
|
| 642 | - * This function has to be run inside the quiz question loop on the single quiz page. |
|
| 643 | - * |
|
| 644 | - * |
|
| 645 | - * @since 1.9.0 |
|
| 646 | - * @param string $question_id |
|
| 647 | - */ |
|
| 648 | - public static function the_answer_result_indication( $question_id ){ |
|
| 641 | + /** |
|
| 642 | + * This function has to be run inside the quiz question loop on the single quiz page. |
|
| 643 | + * |
|
| 644 | + * |
|
| 645 | + * @since 1.9.0 |
|
| 646 | + * @param string $question_id |
|
| 647 | + */ |
|
| 648 | + public static function the_answer_result_indication( $question_id ){ |
|
| 649 | 649 | |
| 650 | - global $post, $current_user, $sensei_question_loop; |
|
| 650 | + global $post, $current_user, $sensei_question_loop; |
|
| 651 | 651 | |
| 652 | - // Post Data |
|
| 653 | - $quiz_id = $sensei_question_loop['quiz_id']; |
|
| 654 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 655 | - $question_item = $sensei_question_loop['current_question']; |
|
| 652 | + // Post Data |
|
| 653 | + $quiz_id = $sensei_question_loop['quiz_id']; |
|
| 654 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 655 | + $question_item = $sensei_question_loop['current_question']; |
|
| 656 | 656 | |
| 657 | - // Setup variable needed to determine if the message should show and what it should show |
|
| 658 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 659 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 660 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 661 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 657 | + // Setup variable needed to determine if the message should show and what it should show |
|
| 658 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 659 | + $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 660 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 661 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 662 | 662 | |
| 663 | - // retrieve the question total grade |
|
| 664 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 663 | + // retrieve the question total grade |
|
| 664 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 665 | 665 | |
| 666 | - // retrieve grade the user achieved |
|
| 667 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
| 666 | + // retrieve grade the user achieved |
|
| 667 | + $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
| 668 | 668 | |
| 669 | - // Question ID |
|
| 670 | - $question_id = $question_item->ID; |
|
| 669 | + // Question ID |
|
| 670 | + $question_id = $question_item->ID; |
|
| 671 | 671 | |
| 672 | - // conditions to check |
|
| 673 | - $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
| 674 | - $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
| 675 | - $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
| 672 | + // conditions to check |
|
| 673 | + $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
| 674 | + $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
| 675 | + $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
| 676 | 676 | |
| 677 | - if ( $completed_with_valid_grade |
|
| 678 | - || $completed_with_valid_grade_and_reset_not_allowed |
|
| 679 | - || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
| 677 | + if ( $completed_with_valid_grade |
|
| 678 | + || $completed_with_valid_grade_and_reset_not_allowed |
|
| 679 | + || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
| 680 | 680 | |
| 681 | - $user_correct = false; |
|
| 682 | - $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
| 683 | - $answer_message_class = 'user_wrong'; |
|
| 684 | - // For zero grade mark as 'correct' but add no classes |
|
| 685 | - if ( 0 == $question_grade ) { |
|
| 681 | + $user_correct = false; |
|
| 682 | + $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
| 683 | + $answer_message_class = 'user_wrong'; |
|
| 684 | + // For zero grade mark as 'correct' but add no classes |
|
| 685 | + if ( 0 == $question_grade ) { |
|
| 686 | 686 | |
| 687 | - $user_correct = true; |
|
| 688 | - $answer_message = ''; |
|
| 689 | - $answer_message_class = ''; |
|
| 687 | + $user_correct = true; |
|
| 688 | + $answer_message = ''; |
|
| 689 | + $answer_message_class = ''; |
|
| 690 | 690 | |
| 691 | - } else if( $user_question_grade > 0 ) { |
|
| 691 | + } else if( $user_question_grade > 0 ) { |
|
| 692 | 692 | |
| 693 | - $user_correct = true; |
|
| 694 | - $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
| 695 | - $answer_message_class = 'user_right'; |
|
| 693 | + $user_correct = true; |
|
| 694 | + $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
| 695 | + $answer_message_class = 'user_right'; |
|
| 696 | 696 | |
| 697 | - } |
|
| 697 | + } |
|
| 698 | 698 | |
| 699 | - // attach the correct answer if the question is auto gradable and user got it wrong |
|
| 700 | - if( !$reset_quiz_allowed && !$user_correct ){ |
|
| 699 | + // attach the correct answer if the question is auto gradable and user got it wrong |
|
| 700 | + if( !$reset_quiz_allowed && !$user_correct ){ |
|
| 701 | 701 | |
| 702 | - $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
| 702 | + $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
| 703 | 703 | |
| 704 | - } |
|
| 704 | + } |
|
| 705 | 705 | |
| 706 | - // answer feedback |
|
| 707 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
| 708 | - if( $answer_notes ) { |
|
| 709 | - $answer_message_class .= ' has_notes'; |
|
| 710 | - } |
|
| 711 | - ?> |
|
| 706 | + // answer feedback |
|
| 707 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
| 708 | + if( $answer_notes ) { |
|
| 709 | + $answer_message_class .= ' has_notes'; |
|
| 710 | + } |
|
| 711 | + ?> |
|
| 712 | 712 | |
| 713 | 713 | <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>"> |
| 714 | 714 | |
@@ -718,387 +718,387 @@ discard block |
||
| 718 | 718 | |
| 719 | 719 | <?php |
| 720 | 720 | |
| 721 | - } // end if user can see all the goodies |
|
| 722 | - |
|
| 723 | - }// end the_answer_result_indication |
|
| 724 | - |
|
| 725 | - /** |
|
| 726 | - * Generate the question template data and return it as an array. |
|
| 727 | - * |
|
| 728 | - * @since 1.9.0 |
|
| 729 | - * |
|
| 730 | - * @param string $question_id |
|
| 731 | - * @param $quiz_id |
|
| 732 | - * @return array $question_data |
|
| 733 | - */ |
|
| 734 | - public static function get_template_data( $question_id, $quiz_id ){ |
|
| 735 | - |
|
| 736 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 737 | - |
|
| 738 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 739 | - //backwards compatibility |
|
| 740 | - if( 'on' == $reset_allowed ) { |
|
| 741 | - $reset_allowed = 1; |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - // Check again that the lesson is complete |
|
| 745 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
| 746 | - $user_lesson_complete = false; |
|
| 747 | - if ( $user_lesson_end ) { |
|
| 748 | - $user_lesson_complete = true; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - //setup the question data |
|
| 752 | - $data[ 'ID' ] = $question_id; |
|
| 753 | - $data[ 'title' ] = get_the_title( $question_id ); |
|
| 754 | - $data[ 'content' ] = get_post( $question_id )->post_content; |
|
| 755 | - $data[ 'quiz_id' ] = $quiz_id; |
|
| 756 | - $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 757 | - $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
| 758 | - $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
| 759 | - $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
| 760 | - $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
| 761 | - $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
| 762 | - $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
| 763 | - $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
| 764 | - $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 765 | - $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
| 766 | - $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
| 767 | - |
|
| 768 | - /** |
|
| 769 | - * Filter the question template data. This filter fires in |
|
| 770 | - * the get_template_data function |
|
| 771 | - * |
|
| 772 | - * @hooked self::boolean_load_question_data |
|
| 773 | - * |
|
| 774 | - * @since 1.9.0 |
|
| 775 | - * |
|
| 776 | - * @param array $data |
|
| 777 | - * @param string $question_id |
|
| 778 | - * @param string $quiz_id |
|
| 779 | - */ |
|
| 780 | - return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
| 721 | + } // end if user can see all the goodies |
|
| 781 | 722 | |
| 782 | - } |
|
| 723 | + }// end the_answer_result_indication |
|
| 783 | 724 | |
| 784 | - /** |
|
| 785 | - * Load multiple choice question data on the sensei_get_question_template_data |
|
| 786 | - * filter. |
|
| 787 | - * |
|
| 788 | - * @since 1.9.0 |
|
| 789 | - * |
|
| 790 | - * @param $question_data |
|
| 791 | - * @param $question_id |
|
| 792 | - * @param $quiz_id |
|
| 793 | - * |
|
| 794 | - * @return array() |
|
| 795 | - */ |
|
| 796 | - public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
| 725 | + /** |
|
| 726 | + * Generate the question template data and return it as an array. |
|
| 727 | + * |
|
| 728 | + * @since 1.9.0 |
|
| 729 | + * |
|
| 730 | + * @param string $question_id |
|
| 731 | + * @param $quiz_id |
|
| 732 | + * @return array $question_data |
|
| 733 | + */ |
|
| 734 | + public static function get_template_data( $question_id, $quiz_id ){ |
|
| 797 | 735 | |
| 736 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 798 | 737 | |
| 799 | - if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 738 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 739 | + //backwards compatibility |
|
| 740 | + if( 'on' == $reset_allowed ) { |
|
| 741 | + $reset_allowed = 1; |
|
| 742 | + } |
|
| 800 | 743 | |
| 801 | - // Get uploaded file |
|
| 802 | - $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
| 803 | - $answer_media_url = $answer_media_filename = ''; |
|
| 744 | + // Check again that the lesson is complete |
|
| 745 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
| 746 | + $user_lesson_complete = false; |
|
| 747 | + if ( $user_lesson_end ) { |
|
| 748 | + $user_lesson_complete = true; |
|
| 749 | + } |
|
| 804 | 750 | |
| 751 | + //setup the question data |
|
| 752 | + $data[ 'ID' ] = $question_id; |
|
| 753 | + $data[ 'title' ] = get_the_title( $question_id ); |
|
| 754 | + $data[ 'content' ] = get_post( $question_id )->post_content; |
|
| 755 | + $data[ 'quiz_id' ] = $quiz_id; |
|
| 756 | + $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 757 | + $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
| 758 | + $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
| 759 | + $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
| 760 | + $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
| 761 | + $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
| 762 | + $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
| 763 | + $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
| 764 | + $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 765 | + $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
| 766 | + $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
| 767 | + |
|
| 768 | + /** |
|
| 769 | + * Filter the question template data. This filter fires in |
|
| 770 | + * the get_template_data function |
|
| 771 | + * |
|
| 772 | + * @hooked self::boolean_load_question_data |
|
| 773 | + * |
|
| 774 | + * @since 1.9.0 |
|
| 775 | + * |
|
| 776 | + * @param array $data |
|
| 777 | + * @param string $question_id |
|
| 778 | + * @param string $quiz_id |
|
| 779 | + */ |
|
| 780 | + return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
| 805 | 781 | |
| 806 | - $question_helptext = ''; |
|
| 807 | - if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
| 782 | + } |
|
| 808 | 783 | |
| 809 | - $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 784 | + /** |
|
| 785 | + * Load multiple choice question data on the sensei_get_question_template_data |
|
| 786 | + * filter. |
|
| 787 | + * |
|
| 788 | + * @since 1.9.0 |
|
| 789 | + * |
|
| 790 | + * @param $question_data |
|
| 791 | + * @param $question_id |
|
| 792 | + * @param $quiz_id |
|
| 793 | + * |
|
| 794 | + * @return array() |
|
| 795 | + */ |
|
| 796 | + public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
| 810 | 797 | |
| 811 | - } |
|
| 812 | 798 | |
| 799 | + if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 813 | 800 | |
| 814 | - if( 0 < intval( $attachment_id ) ) { |
|
| 801 | + // Get uploaded file |
|
| 802 | + $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
| 803 | + $answer_media_url = $answer_media_filename = ''; |
|
| 815 | 804 | |
| 816 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 817 | - $answer_media_filename = basename( $answer_media_url ); |
|
| 818 | 805 | |
| 819 | - } |
|
| 806 | + $question_helptext = ''; |
|
| 807 | + if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
| 820 | 808 | |
| 809 | + $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 821 | 810 | |
| 822 | - // Get max upload file size, formatted for display |
|
| 823 | - // Code copied from wp-admin/includes/media.php:1515 |
|
| 824 | - $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
|
| 825 | - $sizes = array( 'KB', 'MB', 'GB' ); |
|
| 826 | - for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
| 827 | - $upload_size_unit /= 1024; |
|
| 828 | - } |
|
| 829 | - if ( $u < 0 ) { |
|
| 811 | + } |
|
| 830 | 812 | |
| 831 | - $upload_size_unit = 0; |
|
| 832 | - $u = 0; |
|
| 833 | 813 | |
| 834 | - } else { |
|
| 814 | + if( 0 < intval( $attachment_id ) ) { |
|
| 835 | 815 | |
| 836 | - $upload_size_unit = (int) $upload_size_unit; |
|
| 816 | + $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 817 | + $answer_media_filename = basename( $answer_media_url ); |
|
| 837 | 818 | |
| 838 | - } |
|
| 839 | - $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
| 819 | + } |
|
| 840 | 820 | |
| 841 | - // Assemble all the data needed by the file upload template |
|
| 842 | - $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
| 843 | - $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
| 844 | - $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
| 845 | 821 | |
| 846 | - $question_data[ 'question_helptext' ] = $question_helptext; |
|
| 822 | + // Get max upload file size, formatted for display |
|
| 823 | + // Code copied from wp-admin/includes/media.php:1515 |
|
| 824 | + $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
|
| 825 | + $sizes = array( 'KB', 'MB', 'GB' ); |
|
| 826 | + for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
| 827 | + $upload_size_unit /= 1024; |
|
| 828 | + } |
|
| 829 | + if ( $u < 0 ) { |
|
| 847 | 830 | |
| 848 | - }// end if is file upload type |
|
| 831 | + $upload_size_unit = 0; |
|
| 832 | + $u = 0; |
|
| 849 | 833 | |
| 850 | - return $question_data; |
|
| 834 | + } else { |
|
| 851 | 835 | |
| 852 | - }// end file_upload_load_question_data |
|
| 836 | + $upload_size_unit = (int) $upload_size_unit; |
|
| 853 | 837 | |
| 854 | - /** |
|
| 855 | - * Load multiple choice question data on the sensei_get_question_template_data |
|
| 856 | - * filter. |
|
| 857 | - * |
|
| 858 | - * @since 1.9.0 |
|
| 859 | - * |
|
| 860 | - * @param $question_data |
|
| 861 | - * @param $question_id |
|
| 862 | - * @param $quiz_id |
|
| 863 | - * |
|
| 864 | - * @return array() |
|
| 865 | - */ |
|
| 866 | - public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 838 | + } |
|
| 839 | + $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
| 867 | 840 | |
| 868 | - if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 841 | + // Assemble all the data needed by the file upload template |
|
| 842 | + $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
| 843 | + $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
| 844 | + $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
| 869 | 845 | |
| 846 | + $question_data[ 'question_helptext' ] = $question_helptext; |
|
| 870 | 847 | |
| 871 | - $answer_type = 'radio'; |
|
| 872 | - if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
| 848 | + }// end if is file upload type |
|
| 873 | 849 | |
| 874 | - $answer_type = 'checkbox'; |
|
| 850 | + return $question_data; |
|
| 875 | 851 | |
| 876 | - } |
|
| 852 | + }// end file_upload_load_question_data |
|
| 877 | 853 | |
| 878 | - // Merge right and wrong answers |
|
| 879 | - if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
| 854 | + /** |
|
| 855 | + * Load multiple choice question data on the sensei_get_question_template_data |
|
| 856 | + * filter. |
|
| 857 | + * |
|
| 858 | + * @since 1.9.0 |
|
| 859 | + * |
|
| 860 | + * @param $question_data |
|
| 861 | + * @param $question_id |
|
| 862 | + * @param $quiz_id |
|
| 863 | + * |
|
| 864 | + * @return array() |
|
| 865 | + */ |
|
| 866 | + public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 880 | 867 | |
| 881 | - $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 868 | + if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 882 | 869 | |
| 883 | - } else { |
|
| 884 | 870 | |
| 885 | - array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 886 | - $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
| 871 | + $answer_type = 'radio'; |
|
| 872 | + if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
| 887 | 873 | |
| 888 | - } |
|
| 874 | + $answer_type = 'checkbox'; |
|
| 889 | 875 | |
| 890 | - // Setup answer options array. |
|
| 891 | - $question_answers_options = array(); |
|
| 892 | - $count = 0; |
|
| 876 | + } |
|
| 893 | 877 | |
| 894 | - foreach( $merged_options as $answer ) { |
|
| 878 | + // Merge right and wrong answers |
|
| 879 | + if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
| 895 | 880 | |
| 896 | - $count++; |
|
| 897 | - $question_option = array(); |
|
| 881 | + $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 898 | 882 | |
| 899 | - if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 900 | - || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 901 | - || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
| 883 | + } else { |
|
| 902 | 884 | |
| 903 | - $user_correct = false; |
|
| 885 | + array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 886 | + $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
| 904 | 887 | |
| 888 | + } |
|
| 905 | 889 | |
| 906 | - // For zero grade mark as 'correct' but add no classes |
|
| 907 | - if ( 0 == $question_data[ 'question_grade' ] ) { |
|
| 890 | + // Setup answer options array. |
|
| 891 | + $question_answers_options = array(); |
|
| 892 | + $count = 0; |
|
| 908 | 893 | |
| 909 | - $user_correct = true; |
|
| 894 | + foreach( $merged_options as $answer ) { |
|
| 910 | 895 | |
| 911 | - } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 896 | + $count++; |
|
| 897 | + $question_option = array(); |
|
| 912 | 898 | |
| 913 | - $user_correct = true; |
|
| 899 | + if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 900 | + || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 901 | + || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
| 914 | 902 | |
| 915 | - } |
|
| 903 | + $user_correct = false; |
|
| 916 | 904 | |
| 917 | - } |
|
| 918 | 905 | |
| 919 | - // setup the option specific classes |
|
| 920 | - $answer_class = ''; |
|
| 921 | - if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
| 922 | - if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
| 906 | + // For zero grade mark as 'correct' but add no classes |
|
| 907 | + if ( 0 == $question_data[ 'question_grade' ] ) { |
|
| 923 | 908 | |
| 924 | - $answer_class .= ' right_answer'; |
|
| 909 | + $user_correct = true; |
|
| 925 | 910 | |
| 926 | - } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 911 | + } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 927 | 912 | |
| 928 | - $answer_class .= ' right_answer'; |
|
| 913 | + $user_correct = true; |
|
| 929 | 914 | |
| 930 | - } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
| 931 | - || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
| 915 | + } |
|
| 932 | 916 | |
| 933 | - $answer_class = 'user_wrong'; |
|
| 934 | - if( $user_correct ) { |
|
| 917 | + } |
|
| 935 | 918 | |
| 936 | - $answer_class = 'user_right'; |
|
| 919 | + // setup the option specific classes |
|
| 920 | + $answer_class = ''; |
|
| 921 | + if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
| 922 | + if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
| 937 | 923 | |
| 938 | - } |
|
| 924 | + $answer_class .= ' right_answer'; |
|
| 939 | 925 | |
| 940 | - } |
|
| 926 | + } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 941 | 927 | |
| 942 | - } |
|
| 928 | + $answer_class .= ' right_answer'; |
|
| 943 | 929 | |
| 944 | - // determine if the current option must be checked |
|
| 945 | - $checked = ''; |
|
| 946 | - if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
| 947 | - if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
| 930 | + } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
| 931 | + || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
| 948 | 932 | |
| 949 | - $checked = 'checked="checked"'; |
|
| 933 | + $answer_class = 'user_wrong'; |
|
| 934 | + if( $user_correct ) { |
|
| 950 | 935 | |
| 951 | - } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
| 936 | + $answer_class = 'user_right'; |
|
| 952 | 937 | |
| 953 | - $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
| 938 | + } |
|
| 954 | 939 | |
| 955 | - } |
|
| 940 | + } |
|
| 956 | 941 | |
| 957 | - } // End If Statement |
|
| 942 | + } |
|
| 958 | 943 | |
| 959 | - //Load the answer option data |
|
| 960 | - $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
| 961 | - $question_option[ 'answer' ] = $answer; |
|
| 962 | - $question_option[ 'option_class'] = $answer_class; |
|
| 963 | - $question_option[ 'checked'] = $checked; |
|
| 964 | - $question_option[ 'count' ] = $count; |
|
| 965 | - $question_option[ 'type' ] = $answer_type; |
|
| 944 | + // determine if the current option must be checked |
|
| 945 | + $checked = ''; |
|
| 946 | + if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
| 947 | + if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
| 966 | 948 | |
| 967 | - // add the speci fic option to the list of options for this question |
|
| 968 | - $question_answers_options[] = $question_option; |
|
| 949 | + $checked = 'checked="checked"'; |
|
| 969 | 950 | |
| 970 | - } // end for each option |
|
| 951 | + } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
| 971 | 952 | |
| 953 | + $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
| 972 | 954 | |
| 973 | - // Shuffle the array depending on the settings |
|
| 974 | - $answer_options_sorted = array(); |
|
| 975 | - $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
| 976 | - if( $random_order && $random_order == 'yes' ) { |
|
| 955 | + } |
|
| 977 | 956 | |
| 978 | - $answer_options_sorted = $question_answers_options; |
|
| 979 | - shuffle( $answer_options_sorted ); |
|
| 957 | + } // End If Statement |
|
| 980 | 958 | |
| 981 | - } else { |
|
| 959 | + //Load the answer option data |
|
| 960 | + $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
| 961 | + $question_option[ 'answer' ] = $answer; |
|
| 962 | + $question_option[ 'option_class'] = $answer_class; |
|
| 963 | + $question_option[ 'checked'] = $checked; |
|
| 964 | + $question_option[ 'count' ] = $count; |
|
| 965 | + $question_option[ 'type' ] = $answer_type; |
|
| 982 | 966 | |
| 983 | - $answer_order = array(); |
|
| 984 | - $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
| 985 | - if( $answer_order_string ) { |
|
| 967 | + // add the speci fic option to the list of options for this question |
|
| 968 | + $question_answers_options[] = $question_option; |
|
| 986 | 969 | |
| 987 | - $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
| 988 | - if( count( $answer_order ) > 0 ) { |
|
| 970 | + } // end for each option |
|
| 989 | 971 | |
| 990 | - foreach( $answer_order as $answer_id ) { |
|
| 991 | 972 | |
| 992 | - if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
| 973 | + // Shuffle the array depending on the settings |
|
| 974 | + $answer_options_sorted = array(); |
|
| 975 | + $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
| 976 | + if( $random_order && $random_order == 'yes' ) { |
|
| 993 | 977 | |
| 994 | - $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
| 995 | - unset( $question_answers_options[ $answer_id ] ); |
|
| 978 | + $answer_options_sorted = $question_answers_options; |
|
| 979 | + shuffle( $answer_options_sorted ); |
|
| 996 | 980 | |
| 997 | - } |
|
| 981 | + } else { |
|
| 998 | 982 | |
| 999 | - } |
|
| 983 | + $answer_order = array(); |
|
| 984 | + $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
| 985 | + if( $answer_order_string ) { |
|
| 1000 | 986 | |
| 1001 | - if( count( $question_answers_options ) > 0 ) { |
|
| 1002 | - foreach( $question_answers_options as $id => $answer ) { |
|
| 987 | + $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
| 988 | + if( count( $answer_order ) > 0 ) { |
|
| 1003 | 989 | |
| 1004 | - $answer_options_sorted[ $id ] = $answer; |
|
| 990 | + foreach( $answer_order as $answer_id ) { |
|
| 1005 | 991 | |
| 1006 | - } |
|
| 1007 | - } |
|
| 992 | + if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
| 1008 | 993 | |
| 1009 | - }else{ |
|
| 994 | + $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
| 995 | + unset( $question_answers_options[ $answer_id ] ); |
|
| 1010 | 996 | |
| 1011 | - $answer_options_sorted = $question_answers_options; |
|
| 997 | + } |
|
| 1012 | 998 | |
| 1013 | - } |
|
| 999 | + } |
|
| 1014 | 1000 | |
| 1015 | - }else{ |
|
| 1001 | + if( count( $question_answers_options ) > 0 ) { |
|
| 1002 | + foreach( $question_answers_options as $id => $answer ) { |
|
| 1016 | 1003 | |
| 1017 | - $answer_options_sorted = $question_answers_options; |
|
| 1004 | + $answer_options_sorted[ $id ] = $answer; |
|
| 1018 | 1005 | |
| 1019 | - } // end if $answer_order_string |
|
| 1006 | + } |
|
| 1007 | + } |
|
| 1020 | 1008 | |
| 1021 | - } // end if random order |
|
| 1009 | + }else{ |
|
| 1022 | 1010 | |
| 1011 | + $answer_options_sorted = $question_answers_options; |
|
| 1023 | 1012 | |
| 1024 | - // assemble and setup the data for the templates data array |
|
| 1025 | - $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
| 1013 | + } |
|
| 1026 | 1014 | |
| 1027 | - } |
|
| 1015 | + }else{ |
|
| 1028 | 1016 | |
| 1029 | - return $question_data; |
|
| 1017 | + $answer_options_sorted = $question_answers_options; |
|
| 1030 | 1018 | |
| 1031 | - }// end multiple_choice_load_question_data |
|
| 1019 | + } // end if $answer_order_string |
|
| 1032 | 1020 | |
| 1033 | - /** |
|
| 1034 | - * Load the gap fill question data on the sensei_get_question_template_data |
|
| 1035 | - * filter. |
|
| 1036 | - * |
|
| 1037 | - * @since 1.9.0 |
|
| 1038 | - * |
|
| 1039 | - * @param $question_data |
|
| 1040 | - * @param $question_id |
|
| 1041 | - * @param $quiz_id |
|
| 1042 | - * |
|
| 1043 | - * @return array() |
|
| 1044 | - */ |
|
| 1045 | - public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 1021 | + } // end if random order |
|
| 1046 | 1022 | |
| 1047 | - if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 1048 | 1023 | |
| 1049 | - $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
| 1050 | - $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
| 1051 | - $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
| 1052 | - $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
| 1024 | + // assemble and setup the data for the templates data array |
|
| 1025 | + $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
| 1053 | 1026 | |
| 1054 | - } |
|
| 1027 | + } |
|
| 1055 | 1028 | |
| 1056 | - return $question_data; |
|
| 1029 | + return $question_data; |
|
| 1057 | 1030 | |
| 1058 | - }// end gap_fill_load_question_data |
|
| 1031 | + }// end multiple_choice_load_question_data |
|
| 1032 | + |
|
| 1033 | + /** |
|
| 1034 | + * Load the gap fill question data on the sensei_get_question_template_data |
|
| 1035 | + * filter. |
|
| 1036 | + * |
|
| 1037 | + * @since 1.9.0 |
|
| 1038 | + * |
|
| 1039 | + * @param $question_data |
|
| 1040 | + * @param $question_id |
|
| 1041 | + * @param $quiz_id |
|
| 1042 | + * |
|
| 1043 | + * @return array() |
|
| 1044 | + */ |
|
| 1045 | + public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 1046 | + |
|
| 1047 | + if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 1048 | + |
|
| 1049 | + $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
| 1050 | + $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
| 1051 | + $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
| 1052 | + $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
| 1053 | + |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + return $question_data; |
|
| 1057 | + |
|
| 1058 | + }// end gap_fill_load_question_data |
|
| 1059 | 1059 | |
| 1060 | 1060 | |
| 1061 | - /** |
|
| 1062 | - * Get the correct answer for a question |
|
| 1063 | - * |
|
| 1064 | - * @param $question_id |
|
| 1065 | - * @return string $correct_answer or empty |
|
| 1066 | - */ |
|
| 1067 | - public static function get_correct_answer( $question_id ){ |
|
| 1061 | + /** |
|
| 1062 | + * Get the correct answer for a question |
|
| 1063 | + * |
|
| 1064 | + * @param $question_id |
|
| 1065 | + * @return string $correct_answer or empty |
|
| 1066 | + */ |
|
| 1067 | + public static function get_correct_answer( $question_id ){ |
|
| 1068 | 1068 | |
| 1069 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 1070 | - $type = Sensei()->question->get_question_type( $question_id ); |
|
| 1071 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 1072 | - $grade_type = 'manual-grade'; |
|
| 1069 | + $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 1070 | + $type = Sensei()->question->get_question_type( $question_id ); |
|
| 1071 | + $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 1072 | + $grade_type = 'manual-grade'; |
|
| 1073 | 1073 | |
| 1074 | - if ('boolean'== $type ) { |
|
| 1074 | + if ('boolean'== $type ) { |
|
| 1075 | 1075 | |
| 1076 | - $right_answer = ucfirst($right_answer); |
|
| 1076 | + $right_answer = ucfirst($right_answer); |
|
| 1077 | 1077 | |
| 1078 | - }elseif( 'multiple-choice' == $type ) { |
|
| 1078 | + }elseif( 'multiple-choice' == $type ) { |
|
| 1079 | 1079 | |
| 1080 | - $right_answer = (array) $right_answer; |
|
| 1081 | - $right_answer = implode( ', ', $right_answer ); |
|
| 1080 | + $right_answer = (array) $right_answer; |
|
| 1081 | + $right_answer = implode( ', ', $right_answer ); |
|
| 1082 | 1082 | |
| 1083 | - }elseif( 'gap-fill' == $type ) { |
|
| 1083 | + }elseif( 'gap-fill' == $type ) { |
|
| 1084 | 1084 | |
| 1085 | - $right_answer_array = explode( '||', $right_answer ); |
|
| 1086 | - if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1087 | - if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1088 | - if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1085 | + $right_answer_array = explode( '||', $right_answer ); |
|
| 1086 | + if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1087 | + if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1088 | + if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1089 | 1089 | |
| 1090 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
| 1090 | + $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
| 1091 | 1091 | |
| 1092 | - }else{ |
|
| 1092 | + }else{ |
|
| 1093 | 1093 | |
| 1094 | - // for non auto gradable question types no answer should be returned. |
|
| 1095 | - $right_answer = ''; |
|
| 1094 | + // for non auto gradable question types no answer should be returned. |
|
| 1095 | + $right_answer = ''; |
|
| 1096 | 1096 | |
| 1097 | - } |
|
| 1097 | + } |
|
| 1098 | 1098 | |
| 1099 | - return $right_answer; |
|
| 1099 | + return $right_answer; |
|
| 1100 | 1100 | |
| 1101 | - } // get_correct_answer |
|
| 1101 | + } // get_correct_answer |
|
| 1102 | 1102 | |
| 1103 | 1103 | } // End Class |
| 1104 | 1104 | |
@@ -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 Question Class |
@@ -20,34 +20,34 @@ discard block |
||
| 20 | 20 | * Constructor. |
| 21 | 21 | * @since 1.0.0 |
| 22 | 22 | */ |
| 23 | - public function __construct () { |
|
| 23 | + public function __construct() { |
|
| 24 | 24 | $this->question_types = $this->question_types(); |
| 25 | - $this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' ); |
|
| 26 | - if ( is_admin() ) { |
|
| 25 | + $this->meta_fields = array('question_right_answer', 'question_wrong_answers'); |
|
| 26 | + if (is_admin()) { |
|
| 27 | 27 | // Custom Write Panel Columns |
| 28 | - add_filter( 'manage_edit-question_columns', array( $this, 'add_column_headings' ), 10, 1 ); |
|
| 29 | - add_action( 'manage_posts_custom_column', array( $this, 'add_column_data' ), 10, 2 ); |
|
| 30 | - add_action( 'add_meta_boxes', array( $this, 'question_edit_panel_metabox' ), 10, 2 ); |
|
| 28 | + add_filter('manage_edit-question_columns', array($this, 'add_column_headings'), 10, 1); |
|
| 29 | + add_action('manage_posts_custom_column', array($this, 'add_column_data'), 10, 2); |
|
| 30 | + add_action('add_meta_boxes', array($this, 'question_edit_panel_metabox'), 10, 2); |
|
| 31 | 31 | |
| 32 | 32 | // Quesitno list table filters |
| 33 | - add_action( 'restrict_manage_posts', array( $this, 'filter_options' ) ); |
|
| 34 | - add_filter( 'request', array( $this, 'filter_actions' ) ); |
|
| 33 | + add_action('restrict_manage_posts', array($this, 'filter_options')); |
|
| 34 | + add_filter('request', array($this, 'filter_actions')); |
|
| 35 | 35 | |
| 36 | - add_action( 'save_post', array( $this, 'save_question' ), 10, 1 ); |
|
| 36 | + add_action('save_post', array($this, 'save_question'), 10, 1); |
|
| 37 | 37 | } // End If Statement |
| 38 | 38 | } // End __construct() |
| 39 | 39 | |
| 40 | 40 | public function question_types() { |
| 41 | 41 | $types = array( |
| 42 | - 'multiple-choice' => __( 'Multiple Choice', 'woothemes-sensei' ), |
|
| 43 | - 'boolean' => __( 'True/False', 'woothemes-sensei' ), |
|
| 44 | - 'gap-fill' => __( 'Gap Fill', 'woothemes-sensei' ), |
|
| 45 | - 'single-line' => __( 'Single Line', 'woothemes-sensei' ), |
|
| 46 | - 'multi-line' => __( 'Multi Line', 'woothemes-sensei' ), |
|
| 47 | - 'file-upload' => __( 'File Upload', 'woothemes-sensei' ), |
|
| 42 | + 'multiple-choice' => __('Multiple Choice', 'woothemes-sensei'), |
|
| 43 | + 'boolean' => __('True/False', 'woothemes-sensei'), |
|
| 44 | + 'gap-fill' => __('Gap Fill', 'woothemes-sensei'), |
|
| 45 | + 'single-line' => __('Single Line', 'woothemes-sensei'), |
|
| 46 | + 'multi-line' => __('Multi Line', 'woothemes-sensei'), |
|
| 47 | + 'file-upload' => __('File Upload', 'woothemes-sensei'), |
|
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | - return apply_filters( 'sensei_question_types', $types ); |
|
| 50 | + return apply_filters('sensei_question_types', $types); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | * @param array $defaults |
| 58 | 58 | * @return array $new_columns |
| 59 | 59 | */ |
| 60 | - public function add_column_headings ( $defaults ) { |
|
| 60 | + public function add_column_headings($defaults) { |
|
| 61 | 61 | $new_columns['cb'] = '<input type="checkbox" />'; |
| 62 | - $new_columns['title'] = _x( 'Question', 'column name', 'woothemes-sensei' ); |
|
| 63 | - $new_columns['question-type'] = _x( 'Type', 'column name', 'woothemes-sensei' ); |
|
| 64 | - $new_columns['question-category'] = _x( 'Categories', 'column name', 'woothemes-sensei' ); |
|
| 65 | - if ( isset( $defaults['date'] ) ) { |
|
| 62 | + $new_columns['title'] = _x('Question', 'column name', 'woothemes-sensei'); |
|
| 63 | + $new_columns['question-type'] = _x('Type', 'column name', 'woothemes-sensei'); |
|
| 64 | + $new_columns['question-category'] = _x('Categories', 'column name', 'woothemes-sensei'); |
|
| 65 | + if (isset($defaults['date'])) { |
|
| 66 | 66 | $new_columns['date'] = $defaults['date']; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -77,27 +77,27 @@ discard block |
||
| 77 | 77 | * @param int $id |
| 78 | 78 | * @return void |
| 79 | 79 | */ |
| 80 | - public function add_column_data ( $column_name, $id ) { |
|
| 80 | + public function add_column_data($column_name, $id) { |
|
| 81 | 81 | global $wpdb, $post; |
| 82 | 82 | |
| 83 | - switch ( $column_name ) { |
|
| 83 | + switch ($column_name) { |
|
| 84 | 84 | |
| 85 | 85 | case 'id': |
| 86 | 86 | echo $id; |
| 87 | 87 | break; |
| 88 | 88 | |
| 89 | 89 | case 'question-type': |
| 90 | - $question_type = strip_tags( get_the_term_list( $id, 'question-type', '', ', ', '' ) ); |
|
| 90 | + $question_type = strip_tags(get_the_term_list($id, 'question-type', '', ', ', '')); |
|
| 91 | 91 | $output = '—'; |
| 92 | - if( isset( $this->question_types[ $question_type ] ) ) { |
|
| 93 | - $output = $this->question_types[ $question_type ]; |
|
| 92 | + if (isset($this->question_types[$question_type])) { |
|
| 93 | + $output = $this->question_types[$question_type]; |
|
| 94 | 94 | } |
| 95 | 95 | echo $output; |
| 96 | 96 | break; |
| 97 | 97 | |
| 98 | 98 | case 'question-category': |
| 99 | - $output = strip_tags( get_the_term_list( $id, 'question-category', '', ', ', '' ) ); |
|
| 100 | - if( ! $output ) { |
|
| 99 | + $output = strip_tags(get_the_term_list($id, 'question-category', '', ', ', '')); |
|
| 100 | + if ( ! $output) { |
|
| 101 | 101 | $output = '—'; |
| 102 | 102 | } |
| 103 | 103 | echo $output; |
@@ -110,49 +110,49 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | } // End add_column_data() |
| 112 | 112 | |
| 113 | - public function question_edit_panel_metabox( $post_type, $post ) { |
|
| 114 | - if( in_array( $post_type, array( 'question', 'multiple_question' ) ) ) { |
|
| 113 | + public function question_edit_panel_metabox($post_type, $post) { |
|
| 114 | + if (in_array($post_type, array('question', 'multiple_question'))) { |
|
| 115 | 115 | |
| 116 | - $metabox_title = __( 'Question', 'woothemes-sensei' ); |
|
| 116 | + $metabox_title = __('Question', 'woothemes-sensei'); |
|
| 117 | 117 | |
| 118 | - if( isset( $post->ID ) ) { |
|
| 118 | + if (isset($post->ID)) { |
|
| 119 | 119 | |
| 120 | - $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 120 | + $question_type = Sensei()->question->get_question_type($post->ID); |
|
| 121 | 121 | |
| 122 | - if( $question_type ) { |
|
| 123 | - $type = $this->question_types[ $question_type ]; |
|
| 124 | - if( $type ) { |
|
| 122 | + if ($question_type) { |
|
| 123 | + $type = $this->question_types[$question_type]; |
|
| 124 | + if ($type) { |
|
| 125 | 125 | $metabox_title = $type; |
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | - add_meta_box( 'question-edit-panel', $metabox_title, array( $this, 'question_edit_panel' ), 'question', 'normal', 'high' ); |
|
| 130 | - add_meta_box( 'question-lessons-panel', __( 'Quizzes', 'woothemes-sensei' ), array( $this, 'question_lessons_panel' ), 'question', 'side', 'default' ); |
|
| 131 | - add_meta_box( 'multiple-question-lessons-panel', __( 'Quizzes', 'woothemes-sensei' ), array( $this, 'question_lessons_panel' ), 'multiple_question', 'side', 'default' ); |
|
| 129 | + add_meta_box('question-edit-panel', $metabox_title, array($this, 'question_edit_panel'), 'question', 'normal', 'high'); |
|
| 130 | + add_meta_box('question-lessons-panel', __('Quizzes', 'woothemes-sensei'), array($this, 'question_lessons_panel'), 'question', 'side', 'default'); |
|
| 131 | + add_meta_box('multiple-question-lessons-panel', __('Quizzes', 'woothemes-sensei'), array($this, 'question_lessons_panel'), 'multiple_question', 'side', 'default'); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | public function question_edit_panel() { |
| 136 | 136 | global $post, $pagenow; |
| 137 | 137 | |
| 138 | - add_action( 'admin_enqueue_scripts', array( Sensei()->lesson, 'enqueue_scripts' ) ); |
|
| 139 | - add_action( 'admin_enqueue_scripts', array( Sensei()->lesson, 'enqueue_styles' ) ); |
|
| 138 | + add_action('admin_enqueue_scripts', array(Sensei()->lesson, 'enqueue_scripts')); |
|
| 139 | + add_action('admin_enqueue_scripts', array(Sensei()->lesson, 'enqueue_styles')); |
|
| 140 | 140 | |
| 141 | 141 | $html = '<div id="lesson-quiz" class="single-question"><div id="add-question-main">'; |
| 142 | 142 | |
| 143 | - if( 'post-new.php' == $pagenow ) { |
|
| 143 | + if ('post-new.php' == $pagenow) { |
|
| 144 | 144 | |
| 145 | 145 | $html .= '<div id="add-question-actions">'; |
| 146 | - $html .= Sensei()->lesson->quiz_panel_add( 'question' ); |
|
| 146 | + $html .= Sensei()->lesson->quiz_panel_add('question'); |
|
| 147 | 147 | $html .= '</div>'; |
| 148 | 148 | |
| 149 | 149 | } else { |
| 150 | 150 | $question_id = $post->ID; |
| 151 | 151 | |
| 152 | - $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 152 | + $question_type = Sensei()->question->get_question_type($post->ID); |
|
| 153 | 153 | |
| 154 | 154 | $html .= '<div id="add-question-metadata"><table class="widefat">'; |
| 155 | - $html .= Sensei()->lesson->quiz_panel_question( $question_type, 0, $question_id, 'question' ); |
|
| 155 | + $html .= Sensei()->lesson->quiz_panel_question($question_type, 0, $question_id, 'question'); |
|
| 156 | 156 | $html .= '</table></div>'; |
| 157 | 157 | } |
| 158 | 158 | |
@@ -164,20 +164,20 @@ discard block |
||
| 164 | 164 | public function question_lessons_panel() { |
| 165 | 165 | global $post; |
| 166 | 166 | |
| 167 | - $no_lessons = sprintf( __( '%1$sThis question does not appear in any quizzes yet.%2$s', 'woothemes-sensei' ), '<em>', '</em>' ); |
|
| 167 | + $no_lessons = sprintf(__('%1$sThis question does not appear in any quizzes yet.%2$s', 'woothemes-sensei'), '<em>', '</em>'); |
|
| 168 | 168 | |
| 169 | - if( ! isset( $post->ID ) ) { |
|
| 169 | + if ( ! isset($post->ID)) { |
|
| 170 | 170 | echo $no_lessons; |
| 171 | 171 | return; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // This retrieves those quizzes the question is directly connected to. |
| 175 | - $quizzes = get_post_meta( $post->ID, '_quiz_id', false ); |
|
| 175 | + $quizzes = get_post_meta($post->ID, '_quiz_id', false); |
|
| 176 | 176 | |
| 177 | 177 | // Collate all 'multiple_question' quizzes the question is part of. |
| 178 | - $categories_of_question = wp_get_post_terms( $post->ID, 'question-category', array( 'fields' => 'ids' ) ); |
|
| 179 | - if ( ! empty( $categories_of_question ) ) { |
|
| 180 | - foreach ( $categories_of_question as $term_id ) { |
|
| 178 | + $categories_of_question = wp_get_post_terms($post->ID, 'question-category', array('fields' => 'ids')); |
|
| 179 | + if ( ! empty($categories_of_question)) { |
|
| 180 | + foreach ($categories_of_question as $term_id) { |
|
| 181 | 181 | $qargs = array( |
| 182 | 182 | 'fields' => 'ids', |
| 183 | 183 | 'post_type' => 'multiple_question', |
@@ -191,41 +191,41 @@ discard block |
||
| 191 | 191 | 'post_status' => 'any', |
| 192 | 192 | 'suppress_filters' => 0, |
| 193 | 193 | ); |
| 194 | - $cat_question_ids = get_posts( $qargs ); |
|
| 195 | - foreach( $cat_question_ids as $cat_question_id ) { |
|
| 196 | - $cat_quizzes = get_post_meta( $cat_question_id, '_quiz_id', false ); |
|
| 197 | - $quizzes = array_merge( $quizzes, $cat_quizzes ); |
|
| 194 | + $cat_question_ids = get_posts($qargs); |
|
| 195 | + foreach ($cat_question_ids as $cat_question_id) { |
|
| 196 | + $cat_quizzes = get_post_meta($cat_question_id, '_quiz_id', false); |
|
| 197 | + $quizzes = array_merge($quizzes, $cat_quizzes); |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | - $quizzes = array_unique( array_filter( $quizzes ) ); |
|
| 200 | + $quizzes = array_unique(array_filter($quizzes)); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if( 0 == count( $quizzes ) ) { |
|
| 203 | + if (0 == count($quizzes)) { |
|
| 204 | 204 | echo $no_lessons; |
| 205 | 205 | return; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | $lessons = false; |
| 209 | 209 | |
| 210 | - foreach( $quizzes as $quiz ) { |
|
| 210 | + foreach ($quizzes as $quiz) { |
|
| 211 | 211 | |
| 212 | - $lesson_id = get_post_meta( $quiz, '_quiz_lesson', true ); |
|
| 212 | + $lesson_id = get_post_meta($quiz, '_quiz_lesson', true); |
|
| 213 | 213 | |
| 214 | - if( ! $lesson_id ) continue; |
|
| 214 | + if ( ! $lesson_id) continue; |
|
| 215 | 215 | |
| 216 | - $lessons[ $lesson_id ]['title'] = get_the_title( $lesson_id ); |
|
| 217 | - $lessons[ $lesson_id ]['link'] = admin_url( 'post.php?post=' . $lesson_id . '&action=edit' ); |
|
| 216 | + $lessons[$lesson_id]['title'] = get_the_title($lesson_id); |
|
| 217 | + $lessons[$lesson_id]['link'] = admin_url('post.php?post='.$lesson_id.'&action=edit'); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if( ! $lessons ) { |
|
| 220 | + if ( ! $lessons) { |
|
| 221 | 221 | echo $no_lessons; |
| 222 | 222 | return; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | $html = '<ul>'; |
| 226 | 226 | |
| 227 | - foreach( $lessons as $id => $lesson ) { |
|
| 228 | - $html .= '<li><a href="' . esc_url( $lesson['link'] ) . '">' . esc_html( $lesson['title'] ) . '</a></li>'; |
|
| 227 | + foreach ($lessons as $id => $lesson) { |
|
| 228 | + $html .= '<li><a href="'.esc_url($lesson['link']).'">'.esc_html($lesson['title']).'</a></li>'; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | $html .= '</ul>'; |
@@ -234,30 +234,30 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - public function save_question( $post_id = 0 ) { |
|
| 237 | + public function save_question($post_id = 0) { |
|
| 238 | 238 | |
| 239 | - if( ! isset( $_POST['post_type'] |
|
| 240 | - ) || 'question' != $_POST['post_type'] ) { |
|
| 239 | + if ( ! isset($_POST['post_type'] |
|
| 240 | + ) || 'question' != $_POST['post_type']) { |
|
| 241 | 241 | return; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | //setup the data for saving |
| 247 | - $data = $_POST ; |
|
| 247 | + $data = $_POST; |
|
| 248 | 248 | $data['quiz_id'] = 0; |
| 249 | 249 | $data['question_id'] = $post_id; |
| 250 | 250 | |
| 251 | - if ( ! wp_is_post_revision( $post_id ) ){ |
|
| 251 | + if ( ! wp_is_post_revision($post_id)) { |
|
| 252 | 252 | |
| 253 | 253 | // Unhook function to prevent infinite loops |
| 254 | - remove_action( 'save_post', array( $this, 'save_question' ) ); |
|
| 254 | + remove_action('save_post', array($this, 'save_question')); |
|
| 255 | 255 | |
| 256 | 256 | // Update question data |
| 257 | - $question_id = Sensei()->lesson->lesson_save_question( $data, 'question' ); |
|
| 257 | + $question_id = Sensei()->lesson->lesson_save_question($data, 'question'); |
|
| 258 | 258 | |
| 259 | 259 | // Re-hook same function |
| 260 | - add_action( 'save_post', array( $this, 'save_question' ) ); |
|
| 260 | + add_action('save_post', array($this, 'save_question')); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | return; |
@@ -270,15 +270,15 @@ discard block |
||
| 270 | 270 | public function filter_options() { |
| 271 | 271 | global $typenow; |
| 272 | 272 | |
| 273 | - if( is_admin() && 'question' == $typenow ) { |
|
| 273 | + if (is_admin() && 'question' == $typenow) { |
|
| 274 | 274 | |
| 275 | 275 | $output = ''; |
| 276 | 276 | |
| 277 | 277 | // Question type |
| 278 | - $selected = isset( $_GET['question_type'] ) ? $_GET['question_type'] : ''; |
|
| 279 | - $type_options = '<option value="">' . __( 'All types', 'woothemes-sensei' ) . '</option>'; |
|
| 280 | - foreach( $this->question_types as $label => $type ) { |
|
| 281 | - $type_options .= '<option value="' . esc_attr( $label ) . '" ' . selected( $selected, $label, false ) . '>' . esc_html( $type ) . '</option>'; |
|
| 278 | + $selected = isset($_GET['question_type']) ? $_GET['question_type'] : ''; |
|
| 279 | + $type_options = '<option value="">'.__('All types', 'woothemes-sensei').'</option>'; |
|
| 280 | + foreach ($this->question_types as $label => $type) { |
|
| 281 | + $type_options .= '<option value="'.esc_attr($label).'" '.selected($selected, $label, false).'>'.esc_html($type).'</option>'; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | $output .= '<select name="question_type" id="dropdown_question_type">'; |
@@ -286,12 +286,12 @@ discard block |
||
| 286 | 286 | $output .= '</select>'; |
| 287 | 287 | |
| 288 | 288 | // Question category |
| 289 | - $cats = get_terms( 'question-category', array( 'hide_empty' => false ) ); |
|
| 290 | - if ( ! empty( $cats ) && ! is_wp_error( $cats ) ) { |
|
| 291 | - $selected = isset( $_GET['question_cat'] ) ? $_GET['question_cat'] : ''; |
|
| 292 | - $cat_options = '<option value="">' . __( 'All categories', 'woothemes-sensei' ) . '</option>'; |
|
| 293 | - foreach( $cats as $cat ) { |
|
| 294 | - $cat_options .= '<option value="' . esc_attr( $cat->slug ) . '" ' . selected( $selected, $cat->slug, false ) . '>' . esc_html( $cat->name ) . '</option>'; |
|
| 289 | + $cats = get_terms('question-category', array('hide_empty' => false)); |
|
| 290 | + if ( ! empty($cats) && ! is_wp_error($cats)) { |
|
| 291 | + $selected = isset($_GET['question_cat']) ? $_GET['question_cat'] : ''; |
|
| 292 | + $cat_options = '<option value="">'.__('All categories', 'woothemes-sensei').'</option>'; |
|
| 293 | + foreach ($cats as $cat) { |
|
| 294 | + $cat_options .= '<option value="'.esc_attr($cat->slug).'" '.selected($selected, $cat->slug, false).'>'.esc_html($cat->name).'</option>'; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | $output .= '<select name="question_cat" id="dropdown_question_cat">'; |
@@ -308,14 +308,14 @@ discard block |
||
| 308 | 308 | * @param array $request Current request |
| 309 | 309 | * @return array Modified request |
| 310 | 310 | */ |
| 311 | - public function filter_actions( $request ) { |
|
| 311 | + public function filter_actions($request) { |
|
| 312 | 312 | global $typenow; |
| 313 | 313 | |
| 314 | - if( is_admin() && 'question' == $typenow ) { |
|
| 314 | + if (is_admin() && 'question' == $typenow) { |
|
| 315 | 315 | |
| 316 | 316 | // Question type |
| 317 | - $question_type = isset( $_GET['question_type'] ) ? $_GET['question_type'] : ''; |
|
| 318 | - if( $question_type ) { |
|
| 317 | + $question_type = isset($_GET['question_type']) ? $_GET['question_type'] : ''; |
|
| 318 | + if ($question_type) { |
|
| 319 | 319 | $type_query = array( |
| 320 | 320 | 'taxonomy' => 'question-type', |
| 321 | 321 | 'terms' => $question_type, |
@@ -325,8 +325,8 @@ discard block |
||
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | // Question category |
| 328 | - $question_cat = isset( $_GET['question_cat'] ) ? $_GET['question_cat'] : ''; |
|
| 329 | - if( $question_cat ) { |
|
| 328 | + $question_cat = isset($_GET['question_cat']) ? $_GET['question_cat'] : ''; |
|
| 329 | + if ($question_cat) { |
|
| 330 | 330 | $cat_query = array( |
| 331 | 331 | 'taxonomy' => 'question-category', |
| 332 | 332 | 'terms' => $question_cat, |
@@ -351,16 +351,16 @@ discard block |
||
| 351 | 351 | * |
| 352 | 352 | * @return string $question_type | bool |
| 353 | 353 | */ |
| 354 | - public function get_question_type( $question_id ){ |
|
| 354 | + public function get_question_type($question_id) { |
|
| 355 | 355 | |
| 356 | - if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 357 | - || 'question' != get_post_type( $question_id ) ){ |
|
| 356 | + if (empty($question_id) || ! intval($question_id) > 0 |
|
| 357 | + || 'question' != get_post_type($question_id)) { |
|
| 358 | 358 | return false; |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | $question_type = 'multiple-choice'; |
| 362 | - $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
| 363 | - foreach( $question_types as $type ) { |
|
| 362 | + $question_types = wp_get_post_terms($question_id, 'question-type'); |
|
| 363 | + foreach ($question_types as $type) { |
|
| 364 | 364 | $question_type = $type->slug; |
| 365 | 365 | } |
| 366 | 366 | |
@@ -377,21 +377,21 @@ discard block |
||
| 377 | 377 | * |
| 378 | 378 | * @return int $question_grade | bool |
| 379 | 379 | */ |
| 380 | - public function get_question_grade( $question_id ) { |
|
| 380 | + public function get_question_grade($question_id) { |
|
| 381 | 381 | |
| 382 | - if ( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 383 | - || 'question' != get_post_type( $question_id ) ) { |
|
| 382 | + if (empty($question_id) || ! intval($question_id) > 0 |
|
| 383 | + || 'question' != get_post_type($question_id)) { |
|
| 384 | 384 | return false; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - $question_grade_raw = get_post_meta( $question_id, '_question_grade', true ); |
|
| 387 | + $question_grade_raw = get_post_meta($question_id, '_question_grade', true); |
|
| 388 | 388 | // If not set then default to 1... |
| 389 | - if ( false === $question_grade_raw || $question_grade_raw == '' ) { |
|
| 389 | + if (false === $question_grade_raw || $question_grade_raw == '') { |
|
| 390 | 390 | $question_grade = 1; |
| 391 | 391 | } |
| 392 | 392 | // ...but allow a grade of 0 for non-marked questions |
| 393 | 393 | else { |
| 394 | - $question_grade = intval( $question_grade_raw ); |
|
| 394 | + $question_grade = intval($question_grade_raw); |
|
| 395 | 395 | } |
| 396 | 396 | return $question_grade; |
| 397 | 397 | |
@@ -404,9 +404,9 @@ discard block |
||
| 404 | 404 | * @since 1.9.0 |
| 405 | 405 | * @param $question_type |
| 406 | 406 | */ |
| 407 | - public static function load_question_template( $question_type ){ |
|
| 407 | + public static function load_question_template($question_type) { |
|
| 408 | 408 | |
| 409 | - Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 409 | + Sensei_Templates::get_template('single-quiz/question_type-'.$question_type.'.php'); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -417,9 +417,9 @@ discard block |
||
| 417 | 417 | * @since 1.9.0 |
| 418 | 418 | * @param $question_id |
| 419 | 419 | */ |
| 420 | - public static function the_question_title( $question_id ){ |
|
| 420 | + public static function the_question_title($question_id) { |
|
| 421 | 421 | |
| 422 | - echo self::get_the_question_title( $question_id ); |
|
| 422 | + echo self::get_the_question_title($question_id); |
|
| 423 | 423 | |
| 424 | 424 | }// end the_question_title |
| 425 | 425 | |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | * @param $question_id |
| 432 | 432 | * @return string |
| 433 | 433 | */ |
| 434 | - public static function get_the_question_title( $question_id ){ |
|
| 434 | + public static function get_the_question_title($question_id) { |
|
| 435 | 435 | |
| 436 | 436 | /** |
| 437 | 437 | * Filter the sensei question title |
@@ -439,17 +439,17 @@ discard block |
||
| 439 | 439 | * @since 1.3.0 |
| 440 | 440 | * @param $question_title |
| 441 | 441 | */ |
| 442 | - $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
| 442 | + $title = apply_filters('sensei_question_title', get_the_title($question_id)); |
|
| 443 | 443 | |
| 444 | 444 | /** |
| 445 | 445 | * hook document in class-woothemes-sensei-message.php the_title() |
| 446 | 446 | */ |
| 447 | - $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
| 447 | + $title = apply_filters('sensei_single_title', $title, 'question'); |
|
| 448 | 448 | |
| 449 | 449 | $title_html = '<span class="question question-title">'; |
| 450 | 450 | $title_html .= $title; |
| 451 | 451 | $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
| 452 | - $title_html .='</span>'; |
|
| 452 | + $title_html .= '</span>'; |
|
| 453 | 453 | |
| 454 | 454 | return $title_html; |
| 455 | 455 | } |
@@ -460,14 +460,14 @@ discard block |
||
| 460 | 460 | * @param $question_id |
| 461 | 461 | * @return string |
| 462 | 462 | */ |
| 463 | - public static function get_the_question_description( $question_id ){ |
|
| 463 | + public static function get_the_question_description($question_id) { |
|
| 464 | 464 | |
| 465 | - $question = get_post( $question_id ); |
|
| 465 | + $question = get_post($question_id); |
|
| 466 | 466 | |
| 467 | 467 | /** |
| 468 | 468 | * Already documented within WordPress Core |
| 469 | 469 | */ |
| 470 | - return apply_filters( 'the_content', $question->post_content ); |
|
| 470 | + return apply_filters('the_content', $question->post_content); |
|
| 471 | 471 | |
| 472 | 472 | } |
| 473 | 473 | |
@@ -477,9 +477,9 @@ discard block |
||
| 477 | 477 | * @since 1.9.0 |
| 478 | 478 | * @param $question_id |
| 479 | 479 | */ |
| 480 | - public static function the_question_description( $question_id ){ |
|
| 480 | + public static function the_question_description($question_id) { |
|
| 481 | 481 | |
| 482 | - echo self::get_the_question_description( $question_id ); |
|
| 482 | + echo self::get_the_question_description($question_id); |
|
| 483 | 483 | |
| 484 | 484 | } |
| 485 | 485 | |
@@ -490,38 +490,38 @@ discard block |
||
| 490 | 490 | * @param $question_id |
| 491 | 491 | * @return string |
| 492 | 492 | */ |
| 493 | - public static function get_the_question_media( $question_id ){ |
|
| 493 | + public static function get_the_question_media($question_id) { |
|
| 494 | 494 | |
| 495 | - $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
| 495 | + $question_media = get_post_meta($question_id, '_question_media', true); |
|
| 496 | 496 | $question_media_link = ''; |
| 497 | - if( 0 < intval( $question_media ) ) { |
|
| 498 | - $mimetype = get_post_mime_type( $question_media ); |
|
| 499 | - if( $mimetype ) { |
|
| 500 | - $mimetype_array = explode( '/', $mimetype); |
|
| 501 | - if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
| 497 | + if (0 < intval($question_media)) { |
|
| 498 | + $mimetype = get_post_mime_type($question_media); |
|
| 499 | + if ($mimetype) { |
|
| 500 | + $mimetype_array = explode('/', $mimetype); |
|
| 501 | + if (isset($mimetype_array[0]) && $mimetype_array[0]) { |
|
| 502 | 502 | $question_media_type = $mimetype_array[0]; |
| 503 | - $question_media_url = wp_get_attachment_url( $question_media ); |
|
| 504 | - $attachment = get_post( $question_media ); |
|
| 503 | + $question_media_url = wp_get_attachment_url($question_media); |
|
| 504 | + $attachment = get_post($question_media); |
|
| 505 | 505 | $question_media_title = $attachment->post_title; |
| 506 | 506 | $question_media_description = $attachment->post_content; |
| 507 | - switch( $question_media_type ) { |
|
| 507 | + switch ($question_media_type) { |
|
| 508 | 508 | case 'image': |
| 509 | - $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
| 510 | - $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
| 511 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
| 509 | + $image_size = apply_filters('sensei_question_image_size', 'medium', $question_id); |
|
| 510 | + $attachment_src = wp_get_attachment_image_src($question_media, $image_size); |
|
| 511 | + $question_media_link = '<a class="'.esc_attr($question_media_type).'" title="'.esc_attr($question_media_title).'" href="'.esc_url($question_media_url).'" target="_blank"><img src="'.$attachment_src[0].'" width="'.$attachment_src[1].'" height="'.$attachment_src[2].'" /></a>'; |
|
| 512 | 512 | break; |
| 513 | 513 | |
| 514 | 514 | case 'audio': |
| 515 | - $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
| 515 | + $question_media_link = wp_audio_shortcode(array('src' => $question_media_url)); |
|
| 516 | 516 | break; |
| 517 | 517 | |
| 518 | 518 | case 'video': |
| 519 | - $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
| 519 | + $question_media_link = wp_video_shortcode(array('src' => $question_media_url)); |
|
| 520 | 520 | break; |
| 521 | 521 | |
| 522 | 522 | default: |
| 523 | - $question_media_filename = basename( $question_media_url ); |
|
| 524 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
| 523 | + $question_media_filename = basename($question_media_url); |
|
| 524 | + $question_media_link = '<a class="'.esc_attr($question_media_type).'" title="'.esc_attr($question_media_title).'" href="'.esc_url($question_media_url).'" target="_blank">'.$question_media_filename.'</a>'; |
|
| 525 | 525 | break; |
| 526 | 526 | } |
| 527 | 527 | } |
@@ -529,21 +529,21 @@ discard block |
||
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | $output = ''; |
| 532 | - if( $question_media_link ) { |
|
| 532 | + if ($question_media_link) { |
|
| 533 | 533 | |
| 534 | 534 | $output .= '<div class="question_media_display">'; |
| 535 | - $output .= $question_media_link; |
|
| 535 | + $output .= $question_media_link; |
|
| 536 | 536 | $output .= '<dl>'; |
| 537 | 537 | |
| 538 | - if( $question_media_title ) { |
|
| 538 | + if ($question_media_title) { |
|
| 539 | 539 | |
| 540 | - $output .= '<dt>'. $question_media_title. '</dt>'; |
|
| 540 | + $output .= '<dt>'.$question_media_title.'</dt>'; |
|
| 541 | 541 | |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | - if( $question_media_description ) { |
|
| 544 | + if ($question_media_description) { |
|
| 545 | 545 | |
| 546 | - $output .= '<dd>' . $question_media_description . '</dd>'; |
|
| 546 | + $output .= '<dd>'.$question_media_description.'</dd>'; |
|
| 547 | 547 | |
| 548 | 548 | } |
| 549 | 549 | |
@@ -564,9 +564,9 @@ discard block |
||
| 564 | 564 | * @since 1.9.0 |
| 565 | 565 | * @param string $question_id |
| 566 | 566 | */ |
| 567 | - public static function the_question_media( $question_id ){ |
|
| 567 | + public static function the_question_media($question_id) { |
|
| 568 | 568 | |
| 569 | - echo self::get_the_question_media( $question_id ); |
|
| 569 | + echo self::get_the_question_media($question_id); |
|
| 570 | 570 | |
| 571 | 571 | } |
| 572 | 572 | |
@@ -577,11 +577,11 @@ discard block |
||
| 577 | 577 | * |
| 578 | 578 | * @param $question_id |
| 579 | 579 | */ |
| 580 | - public static function the_question_hidden_fields( $question_id ){ |
|
| 580 | + public static function the_question_hidden_fields($question_id) { |
|
| 581 | 581 | ?> |
| 582 | 582 | |
| 583 | - <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" /> |
|
| 584 | - <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" /> |
|
| 583 | + <input type="hidden" name="question_id_<?php $question_id; ?>" value="<?php $question_id; ?>" /> |
|
| 584 | + <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e($question_id); ?>" /> |
|
| 585 | 585 | |
| 586 | 586 | <?php |
| 587 | 587 | } |
@@ -592,27 +592,27 @@ discard block |
||
| 592 | 592 | * @since 1.9.0 |
| 593 | 593 | * @param $question_id |
| 594 | 594 | */ |
| 595 | - public static function answer_feedback_notes( $question_id ){ |
|
| 595 | + public static function answer_feedback_notes($question_id) { |
|
| 596 | 596 | |
| 597 | 597 | //IDS |
| 598 | 598 | $quiz_id = get_the_ID(); |
| 599 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 599 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 600 | 600 | |
| 601 | 601 | // Data to check before showing feedback |
| 602 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
| 603 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 604 | - $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
| 605 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 606 | - $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
| 607 | - $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 602 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, get_current_user_id()); |
|
| 603 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade($lesson_id, get_current_user_id()); |
|
| 604 | + $not_empty_user_quiz_grade = ! empty($user_quiz_grade); |
|
| 605 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed($lesson_id); |
|
| 606 | + $lesson_completed = Sensei_Utils::user_completed_lesson($lesson_id); |
|
| 607 | + $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
| 608 | 608 | |
| 609 | - if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
| 610 | - || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
| 611 | - || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
| 609 | + if (($lesson_completed && $not_empty_user_quiz_grade) |
|
| 610 | + || ($lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type) |
|
| 611 | + || ('auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade)) { |
|
| 612 | 612 | |
| 613 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
| 613 | + $answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, get_current_user_id()); |
|
| 614 | 614 | |
| 615 | - if( $answer_notes ) { ?> |
|
| 615 | + if ($answer_notes) { ?> |
|
| 616 | 616 | |
| 617 | 617 | <div class="sensei-message info info-special answer-feedback"> |
| 618 | 618 | |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | * @param string $question_id |
| 627 | 627 | * @param string $lesson_id |
| 628 | 628 | */ |
| 629 | - echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
| 629 | + echo apply_filters('sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id); |
|
| 630 | 630 | |
| 631 | 631 | ?> |
| 632 | 632 | |
@@ -645,72 +645,72 @@ discard block |
||
| 645 | 645 | * @since 1.9.0 |
| 646 | 646 | * @param string $question_id |
| 647 | 647 | */ |
| 648 | - public static function the_answer_result_indication( $question_id ){ |
|
| 648 | + public static function the_answer_result_indication($question_id) { |
|
| 649 | 649 | |
| 650 | - global $post, $current_user, $sensei_question_loop; |
|
| 650 | + global $post, $current_user, $sensei_question_loop; |
|
| 651 | 651 | |
| 652 | 652 | // Post Data |
| 653 | 653 | $quiz_id = $sensei_question_loop['quiz_id']; |
| 654 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 654 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 655 | 655 | $question_item = $sensei_question_loop['current_question']; |
| 656 | 656 | |
| 657 | 657 | // Setup variable needed to determine if the message should show and what it should show |
| 658 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 659 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 660 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 661 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 658 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade($lesson_id, get_current_user_id()); |
|
| 659 | + $lesson_complete = Sensei_Utils::user_completed_lesson($lesson_id, get_current_user_id()); |
|
| 660 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed($lesson_id); |
|
| 661 | + $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
| 662 | 662 | |
| 663 | 663 | // retrieve the question total grade |
| 664 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 664 | + $question_grade = Sensei()->question->get_question_grade($question_id); |
|
| 665 | 665 | |
| 666 | 666 | // retrieve grade the user achieved |
| 667 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
| 667 | + $user_question_grade = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, get_current_user_id()); |
|
| 668 | 668 | |
| 669 | 669 | // Question ID |
| 670 | 670 | $question_id = $question_item->ID; |
| 671 | 671 | |
| 672 | 672 | // conditions to check |
| 673 | - $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
| 674 | - $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
| 675 | - $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
| 673 | + $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != ''; |
|
| 674 | + $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed; |
|
| 675 | + $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != ''; |
|
| 676 | 676 | |
| 677 | - if ( $completed_with_valid_grade |
|
| 677 | + if ($completed_with_valid_grade |
|
| 678 | 678 | || $completed_with_valid_grade_and_reset_not_allowed |
| 679 | - || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
| 679 | + || $grade_type_auto_a_valid_grade_and_reset_not_allowed) { |
|
| 680 | 680 | |
| 681 | 681 | $user_correct = false; |
| 682 | - $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
| 682 | + $answer_message = __('Incorrect', 'woothemes-sensei'); |
|
| 683 | 683 | $answer_message_class = 'user_wrong'; |
| 684 | 684 | // For zero grade mark as 'correct' but add no classes |
| 685 | - if ( 0 == $question_grade ) { |
|
| 685 | + if (0 == $question_grade) { |
|
| 686 | 686 | |
| 687 | 687 | $user_correct = true; |
| 688 | 688 | $answer_message = ''; |
| 689 | 689 | $answer_message_class = ''; |
| 690 | 690 | |
| 691 | - } else if( $user_question_grade > 0 ) { |
|
| 691 | + } else if ($user_question_grade > 0) { |
|
| 692 | 692 | |
| 693 | 693 | $user_correct = true; |
| 694 | - $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
| 694 | + $answer_message = sprintf(__('Grade: %d', 'woothemes-sensei'), $user_question_grade); |
|
| 695 | 695 | $answer_message_class = 'user_right'; |
| 696 | 696 | |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | // attach the correct answer if the question is auto gradable and user got it wrong |
| 700 | - if( !$reset_quiz_allowed && !$user_correct ){ |
|
| 700 | + if ( ! $reset_quiz_allowed && ! $user_correct) { |
|
| 701 | 701 | |
| 702 | - $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
| 702 | + $answer_message .= ' - '.__('Right Answer:', 'woothemes-sensei').' '.self::get_correct_answer($question_item->ID); |
|
| 703 | 703 | |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | // answer feedback |
| 707 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
| 708 | - if( $answer_notes ) { |
|
| 707 | + $answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, $current_user->ID); |
|
| 708 | + if ($answer_notes) { |
|
| 709 | 709 | $answer_message_class .= ' has_notes'; |
| 710 | 710 | } |
| 711 | 711 | ?> |
| 712 | 712 | |
| 713 | - <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>"> |
|
| 713 | + <div class="answer_message <?php esc_attr_e($answer_message_class); ?>"> |
|
| 714 | 714 | |
| 715 | 715 | <span><?php echo $answer_message; ?></span> |
| 716 | 716 | |
@@ -731,39 +731,39 @@ discard block |
||
| 731 | 731 | * @param $quiz_id |
| 732 | 732 | * @return array $question_data |
| 733 | 733 | */ |
| 734 | - public static function get_template_data( $question_id, $quiz_id ){ |
|
| 734 | + public static function get_template_data($question_id, $quiz_id) { |
|
| 735 | 735 | |
| 736 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 736 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 737 | 737 | |
| 738 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 738 | + $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true); |
|
| 739 | 739 | //backwards compatibility |
| 740 | - if( 'on' == $reset_allowed ) { |
|
| 740 | + if ('on' == $reset_allowed) { |
|
| 741 | 741 | $reset_allowed = 1; |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | // Check again that the lesson is complete |
| 745 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
| 745 | + $user_lesson_end = Sensei_Utils::user_completed_lesson(Sensei()->quiz->get_lesson_id($quiz_id), get_current_user_id()); |
|
| 746 | 746 | $user_lesson_complete = false; |
| 747 | - if ( $user_lesson_end ) { |
|
| 747 | + if ($user_lesson_end) { |
|
| 748 | 748 | $user_lesson_complete = true; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | //setup the question data |
| 752 | - $data[ 'ID' ] = $question_id; |
|
| 753 | - $data[ 'title' ] = get_the_title( $question_id ); |
|
| 754 | - $data[ 'content' ] = get_post( $question_id )->post_content; |
|
| 755 | - $data[ 'quiz_id' ] = $quiz_id; |
|
| 756 | - $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 757 | - $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
| 758 | - $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
| 759 | - $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
| 760 | - $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
| 761 | - $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
| 762 | - $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
| 763 | - $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
| 764 | - $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 765 | - $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
| 766 | - $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
| 752 | + $data['ID'] = $question_id; |
|
| 753 | + $data['title'] = get_the_title($question_id); |
|
| 754 | + $data['content'] = get_post($question_id)->post_content; |
|
| 755 | + $data['quiz_id'] = $quiz_id; |
|
| 756 | + $data['lesson_id'] = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 757 | + $data['type'] = Sensei()->question->get_question_type($question_id); |
|
| 758 | + $data['question_grade'] = Sensei()->question->get_question_grade($question_id); |
|
| 759 | + $data['user_question_grade'] = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, get_current_user_id()); |
|
| 760 | + $data['question_right_answer'] = get_post_meta($question_id, '_question_right_answer', true); |
|
| 761 | + $data['question_wrong_answers'] = get_post_meta($question_id, '_question_wrong_answers', true); |
|
| 762 | + $data['user_answer_entry'] = Sensei()->quiz->get_user_question_answer($lesson_id, $question_id, get_current_user_id()); |
|
| 763 | + $data['lesson_completed'] = Sensei_Utils::user_completed_course($lesson_id, get_current_user_id( )); |
|
| 764 | + $data['quiz_grade_type'] = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
| 765 | + $data['reset_quiz_allowed'] = $reset_allowed; |
|
| 766 | + $data['lesson_complete'] = $user_lesson_complete; |
|
| 767 | 767 | |
| 768 | 768 | /** |
| 769 | 769 | * Filter the question template data. This filter fires in |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | * @param string $question_id |
| 778 | 778 | * @param string $quiz_id |
| 779 | 779 | */ |
| 780 | - return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
| 780 | + return apply_filters('sensei_get_question_template_data', $data, $question_id, $quiz_id); |
|
| 781 | 781 | |
| 782 | 782 | } |
| 783 | 783 | |
@@ -793,28 +793,28 @@ discard block |
||
| 793 | 793 | * |
| 794 | 794 | * @return array() |
| 795 | 795 | */ |
| 796 | - public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
| 796 | + public static function file_upload_load_question_data($question_data, $question_id, $quiz_id) { |
|
| 797 | 797 | |
| 798 | 798 | |
| 799 | - if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 799 | + if ('file-upload' == Sensei()->question->get_question_type($question_id)) { |
|
| 800 | 800 | |
| 801 | 801 | // Get uploaded file |
| 802 | - $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
| 802 | + $attachment_id = $question_data['user_answer_entry']; |
|
| 803 | 803 | $answer_media_url = $answer_media_filename = ''; |
| 804 | 804 | |
| 805 | 805 | |
| 806 | 806 | $question_helptext = ''; |
| 807 | - if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
| 807 | + if (isset($question_data['question_wrong_answers'][0])) { |
|
| 808 | 808 | |
| 809 | - $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 809 | + $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 810 | 810 | |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | |
| 814 | - if( 0 < intval( $attachment_id ) ) { |
|
| 814 | + if (0 < intval($attachment_id)) { |
|
| 815 | 815 | |
| 816 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 817 | - $answer_media_filename = basename( $answer_media_url ); |
|
| 816 | + $answer_media_url = wp_get_attachment_url($attachment_id); |
|
| 817 | + $answer_media_filename = basename($answer_media_url); |
|
| 818 | 818 | |
| 819 | 819 | } |
| 820 | 820 | |
@@ -822,11 +822,11 @@ discard block |
||
| 822 | 822 | // Get max upload file size, formatted for display |
| 823 | 823 | // Code copied from wp-admin/includes/media.php:1515 |
| 824 | 824 | $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
| 825 | - $sizes = array( 'KB', 'MB', 'GB' ); |
|
| 826 | - for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
| 825 | + $sizes = array('KB', 'MB', 'GB'); |
|
| 826 | + for ($u = -1; $upload_size_unit > 1024 && $u < count($sizes) - 1; $u++) { |
|
| 827 | 827 | $upload_size_unit /= 1024; |
| 828 | 828 | } |
| 829 | - if ( $u < 0 ) { |
|
| 829 | + if ($u < 0) { |
|
| 830 | 830 | |
| 831 | 831 | $upload_size_unit = 0; |
| 832 | 832 | $u = 0; |
@@ -836,14 +836,14 @@ discard block |
||
| 836 | 836 | $upload_size_unit = (int) $upload_size_unit; |
| 837 | 837 | |
| 838 | 838 | } |
| 839 | - $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
| 839 | + $max_upload_size = sprintf(__('Maximum upload file size: %d%s'), esc_html($upload_size_unit), esc_html($sizes[$u])); |
|
| 840 | 840 | |
| 841 | 841 | // Assemble all the data needed by the file upload template |
| 842 | - $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
| 843 | - $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
| 844 | - $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
| 842 | + $question_data['answer_media_url'] = $answer_media_url; |
|
| 843 | + $question_data['answer_media_filename'] = $answer_media_filename; |
|
| 844 | + $question_data['max_upload_size'] = $max_upload_size; |
|
| 845 | 845 | |
| 846 | - $question_data[ 'question_helptext' ] = $question_helptext; |
|
| 846 | + $question_data['question_helptext'] = $question_helptext; |
|
| 847 | 847 | |
| 848 | 848 | }// end if is file upload type |
| 849 | 849 | |
@@ -863,27 +863,27 @@ discard block |
||
| 863 | 863 | * |
| 864 | 864 | * @return array() |
| 865 | 865 | */ |
| 866 | - public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 866 | + public static function multiple_choice_load_question_data($question_data, $question_id, $quiz_id) { |
|
| 867 | 867 | |
| 868 | - if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 868 | + if ('multiple-choice' == Sensei()->question->get_question_type($question_id)) { |
|
| 869 | 869 | |
| 870 | 870 | |
| 871 | 871 | $answer_type = 'radio'; |
| 872 | - if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
| 872 | + if (is_array($question_data['question_right_answer']) && (1 < count($question_data['question_right_answer']))) { |
|
| 873 | 873 | |
| 874 | 874 | $answer_type = 'checkbox'; |
| 875 | 875 | |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | // Merge right and wrong answers |
| 879 | - if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
| 879 | + if (is_array($question_data['question_right_answer'])) { |
|
| 880 | 880 | |
| 881 | - $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 881 | + $merged_options = array_merge($question_data['question_wrong_answers'], $question_data['question_right_answer']); |
|
| 882 | 882 | |
| 883 | - } else { |
|
| 883 | + } else { |
|
| 884 | 884 | |
| 885 | - array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 886 | - $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
| 885 | + array_push($question_data['question_wrong_answers'], $question_data['question_right_answer']); |
|
| 886 | + $merged_options = $question_data['question_wrong_answers']; |
|
| 887 | 887 | |
| 888 | 888 | } |
| 889 | 889 | |
@@ -891,24 +891,24 @@ discard block |
||
| 891 | 891 | $question_answers_options = array(); |
| 892 | 892 | $count = 0; |
| 893 | 893 | |
| 894 | - foreach( $merged_options as $answer ) { |
|
| 894 | + foreach ($merged_options as $answer) { |
|
| 895 | 895 | |
| 896 | 896 | $count++; |
| 897 | 897 | $question_option = array(); |
| 898 | 898 | |
| 899 | - if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 900 | - || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 901 | - || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
| 899 | + if (($question_data['lesson_completed'] && $question_data['user_quiz_grade'] != '') |
|
| 900 | + || ($question_data['lesson_completed'] && ! $question_data['reset_quiz_allowed'] && $question_data['user_quiz_grade'] != '') |
|
| 901 | + || ('auto' == $question_data['quiz_grade_type'] && ! $question_data['reset_quiz_allowed'] && ! empty($question_data['user_quiz_grade']))) { |
|
| 902 | 902 | |
| 903 | 903 | $user_correct = false; |
| 904 | 904 | |
| 905 | 905 | |
| 906 | 906 | // For zero grade mark as 'correct' but add no classes |
| 907 | - if ( 0 == $question_data[ 'question_grade' ] ) { |
|
| 907 | + if (0 == $question_data['question_grade']) { |
|
| 908 | 908 | |
| 909 | 909 | $user_correct = true; |
| 910 | 910 | |
| 911 | - } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 911 | + } else if ($question_data['user_question_grade'] > 0) { |
|
| 912 | 912 | |
| 913 | 913 | $user_correct = true; |
| 914 | 914 | |
@@ -918,20 +918,20 @@ discard block |
||
| 918 | 918 | |
| 919 | 919 | // setup the option specific classes |
| 920 | 920 | $answer_class = ''; |
| 921 | - if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
| 922 | - if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
| 921 | + if (isset($user_correct) && 0 < $question_data['question_grade']) { |
|
| 922 | + if (is_array($question_data['question_right_answer']) && in_array($answer, $question_data['question_right_answer'])) { |
|
| 923 | 923 | |
| 924 | 924 | $answer_class .= ' right_answer'; |
| 925 | 925 | |
| 926 | - } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 926 | + } elseif ( ! is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer) { |
|
| 927 | 927 | |
| 928 | 928 | $answer_class .= ' right_answer'; |
| 929 | 929 | |
| 930 | - } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
| 931 | - || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
| 930 | + } elseif ((is_array($question_data['user_answer_entry']) && in_array($answer, $question_data['user_answer_entry'])) |
|
| 931 | + || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer)) { |
|
| 932 | 932 | |
| 933 | 933 | $answer_class = 'user_wrong'; |
| 934 | - if( $user_correct ) { |
|
| 934 | + if ($user_correct) { |
|
| 935 | 935 | |
| 936 | 936 | $answer_class = 'user_right'; |
| 937 | 937 | |
@@ -943,26 +943,26 @@ discard block |
||
| 943 | 943 | |
| 944 | 944 | // determine if the current option must be checked |
| 945 | 945 | $checked = ''; |
| 946 | - if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
| 947 | - if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
| 946 | + if (isset($question_data['user_answer_entry']) && 0 < count($question_data['user_answer_entry'])) { |
|
| 947 | + if (is_array($question_data['user_answer_entry']) && in_array($answer, $question_data['user_answer_entry'])) { |
|
| 948 | 948 | |
| 949 | 949 | $checked = 'checked="checked"'; |
| 950 | 950 | |
| 951 | - } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
| 951 | + } elseif ( ! is_array($question_data['user_answer_entry'])) { |
|
| 952 | 952 | |
| 953 | - $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
| 953 | + $checked = checked($answer, $question_data['user_answer_entry'], false); |
|
| 954 | 954 | |
| 955 | 955 | } |
| 956 | 956 | |
| 957 | 957 | } // End If Statement |
| 958 | 958 | |
| 959 | 959 | //Load the answer option data |
| 960 | - $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
| 961 | - $question_option[ 'answer' ] = $answer; |
|
| 962 | - $question_option[ 'option_class'] = $answer_class; |
|
| 963 | - $question_option[ 'checked'] = $checked; |
|
| 964 | - $question_option[ 'count' ] = $count; |
|
| 965 | - $question_option[ 'type' ] = $answer_type; |
|
| 960 | + $question_option['ID'] = Sensei()->lesson->get_answer_id($answer); |
|
| 961 | + $question_option['answer'] = $answer; |
|
| 962 | + $question_option['option_class'] = $answer_class; |
|
| 963 | + $question_option['checked'] = $checked; |
|
| 964 | + $question_option['count'] = $count; |
|
| 965 | + $question_option['type'] = $answer_type; |
|
| 966 | 966 | |
| 967 | 967 | // add the speci fic option to the list of options for this question |
| 968 | 968 | $question_answers_options[] = $question_option; |
@@ -972,47 +972,47 @@ discard block |
||
| 972 | 972 | |
| 973 | 973 | // Shuffle the array depending on the settings |
| 974 | 974 | $answer_options_sorted = array(); |
| 975 | - $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
| 976 | - if( $random_order && $random_order == 'yes' ) { |
|
| 975 | + $random_order = get_post_meta($question_data['ID'], '_random_order', true); |
|
| 976 | + if ($random_order && $random_order == 'yes') { |
|
| 977 | 977 | |
| 978 | 978 | $answer_options_sorted = $question_answers_options; |
| 979 | - shuffle( $answer_options_sorted ); |
|
| 979 | + shuffle($answer_options_sorted); |
|
| 980 | 980 | |
| 981 | 981 | } else { |
| 982 | 982 | |
| 983 | 983 | $answer_order = array(); |
| 984 | - $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
| 985 | - if( $answer_order_string ) { |
|
| 984 | + $answer_order_string = get_post_meta($question_data['ID'], '_answer_order', true); |
|
| 985 | + if ($answer_order_string) { |
|
| 986 | 986 | |
| 987 | - $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
| 988 | - if( count( $answer_order ) > 0 ) { |
|
| 987 | + $answer_order = array_filter(explode(',', $answer_order_string)); |
|
| 988 | + if (count($answer_order) > 0) { |
|
| 989 | 989 | |
| 990 | - foreach( $answer_order as $answer_id ) { |
|
| 990 | + foreach ($answer_order as $answer_id) { |
|
| 991 | 991 | |
| 992 | - if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
| 992 | + if (isset($question_answers_options[$answer_id])) { |
|
| 993 | 993 | |
| 994 | - $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
| 995 | - unset( $question_answers_options[ $answer_id ] ); |
|
| 994 | + $answer_options_sorted[$answer_id] = $question_answers_options[$answer_id]; |
|
| 995 | + unset($question_answers_options[$answer_id]); |
|
| 996 | 996 | |
| 997 | 997 | } |
| 998 | 998 | |
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | - if( count( $question_answers_options ) > 0 ) { |
|
| 1002 | - foreach( $question_answers_options as $id => $answer ) { |
|
| 1001 | + if (count($question_answers_options) > 0) { |
|
| 1002 | + foreach ($question_answers_options as $id => $answer) { |
|
| 1003 | 1003 | |
| 1004 | - $answer_options_sorted[ $id ] = $answer; |
|
| 1004 | + $answer_options_sorted[$id] = $answer; |
|
| 1005 | 1005 | |
| 1006 | 1006 | } |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | - }else{ |
|
| 1009 | + } else { |
|
| 1010 | 1010 | |
| 1011 | 1011 | $answer_options_sorted = $question_answers_options; |
| 1012 | 1012 | |
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | - }else{ |
|
| 1015 | + } else { |
|
| 1016 | 1016 | |
| 1017 | 1017 | $answer_options_sorted = $question_answers_options; |
| 1018 | 1018 | |
@@ -1022,7 +1022,7 @@ discard block |
||
| 1022 | 1022 | |
| 1023 | 1023 | |
| 1024 | 1024 | // assemble and setup the data for the templates data array |
| 1025 | - $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
| 1025 | + $question_data['answer_options'] = $answer_options_sorted; |
|
| 1026 | 1026 | |
| 1027 | 1027 | } |
| 1028 | 1028 | |
@@ -1042,14 +1042,14 @@ discard block |
||
| 1042 | 1042 | * |
| 1043 | 1043 | * @return array() |
| 1044 | 1044 | */ |
| 1045 | - public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 1045 | + public static function gap_fill_load_question_data($question_data, $question_id, $quiz_id) { |
|
| 1046 | 1046 | |
| 1047 | - if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 1047 | + if ('gap-fill' == Sensei()->question->get_question_type($question_id)) { |
|
| 1048 | 1048 | |
| 1049 | - $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
| 1050 | - $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
| 1051 | - $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
| 1052 | - $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
| 1049 | + $gapfill_array = explode('||', $question_data['question_right_answer']); |
|
| 1050 | + $question_data['gapfill_pre'] = isset($gapfill_array[0]) ? $gapfill_array[0] : ''; |
|
| 1051 | + $question_data['gapfill_gap'] = isset($gapfill_array[1]) ? $gapfill_array[1] : ''; |
|
| 1052 | + $question_data['gapfill_post'] = isset($gapfill_array[2]) ? $gapfill_array[2] : ''; |
|
| 1053 | 1053 | |
| 1054 | 1054 | } |
| 1055 | 1055 | |
@@ -1064,32 +1064,32 @@ discard block |
||
| 1064 | 1064 | * @param $question_id |
| 1065 | 1065 | * @return string $correct_answer or empty |
| 1066 | 1066 | */ |
| 1067 | - public static function get_correct_answer( $question_id ){ |
|
| 1067 | + public static function get_correct_answer($question_id) { |
|
| 1068 | 1068 | |
| 1069 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 1070 | - $type = Sensei()->question->get_question_type( $question_id ); |
|
| 1071 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 1069 | + $right_answer = get_post_meta($question_id, '_question_right_answer', true); |
|
| 1070 | + $type = Sensei()->question->get_question_type($question_id); |
|
| 1071 | + $type_name = __('Multiple Choice', 'woothemes-sensei'); |
|
| 1072 | 1072 | $grade_type = 'manual-grade'; |
| 1073 | 1073 | |
| 1074 | - if ('boolean'== $type ) { |
|
| 1074 | + if ('boolean' == $type) { |
|
| 1075 | 1075 | |
| 1076 | 1076 | $right_answer = ucfirst($right_answer); |
| 1077 | 1077 | |
| 1078 | - }elseif( 'multiple-choice' == $type ) { |
|
| 1078 | + }elseif ('multiple-choice' == $type) { |
|
| 1079 | 1079 | |
| 1080 | 1080 | $right_answer = (array) $right_answer; |
| 1081 | - $right_answer = implode( ', ', $right_answer ); |
|
| 1081 | + $right_answer = implode(', ', $right_answer); |
|
| 1082 | 1082 | |
| 1083 | - }elseif( 'gap-fill' == $type ) { |
|
| 1083 | + }elseif ('gap-fill' == $type) { |
|
| 1084 | 1084 | |
| 1085 | - $right_answer_array = explode( '||', $right_answer ); |
|
| 1086 | - if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1087 | - if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1088 | - if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1085 | + $right_answer_array = explode('||', $right_answer); |
|
| 1086 | + if (isset($right_answer_array[0])) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1087 | + if (isset($right_answer_array[1])) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1088 | + if (isset($right_answer_array[2])) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1089 | 1089 | |
| 1090 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
| 1090 | + $right_answer = $gapfill_pre.' <span class="highlight">'.$gapfill_gap.'</span> '.$gapfill_post; |
|
| 1091 | 1091 | |
| 1092 | - }else{ |
|
| 1092 | + } else { |
|
| 1093 | 1093 | |
| 1094 | 1094 | // for non auto gradable question types no answer should be returned. |
| 1095 | 1095 | $right_answer = ''; |
@@ -1107,4 +1107,4 @@ discard block |
||
| 1107 | 1107 | * for backward compatibility |
| 1108 | 1108 | * @since 1.9.0 |
| 1109 | 1109 | */ |
| 1110 | -class WooThemes_Sensei_Question extends Sensei_Question{} |
|
| 1110 | +class WooThemes_Sensei_Question extends Sensei_Question {} |
|
@@ -10,323 +10,323 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | class Sensei_Legacy_Shortcodes { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Add the legacy shortcodes to WordPress |
|
| 15 | - * |
|
| 16 | - * @since 1.9.0 |
|
| 17 | - */ |
|
| 18 | - public static function init(){ |
|
| 19 | - |
|
| 20 | - add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); |
|
| 21 | - add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); |
|
| 22 | - add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); |
|
| 23 | - add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); |
|
| 24 | - add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); |
|
| 25 | - add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); |
|
| 26 | - |
|
| 27 | - } |
|
| 28 | - /** |
|
| 29 | - * all_courses shortcode output function. |
|
| 30 | - * |
|
| 31 | - * The function should only be called indirectly through do_shortcode() |
|
| 32 | - * |
|
| 33 | - * @access public |
|
| 34 | - * @param mixed $atts |
|
| 35 | - * @param mixed $content (default: null) |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public static function all_courses( $atts, $content = null ) { |
|
| 39 | - |
|
| 40 | - return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title |
|
| 41 | - |
|
| 42 | - } // all_courses() |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * paid_courses function. |
|
| 46 | - * |
|
| 47 | - * @access public |
|
| 48 | - * @param mixed $atts |
|
| 49 | - * @param mixed $content (default: null) |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 52 | - public static function paid_courses( $atts, $content = null ) { |
|
| 53 | - |
|
| 54 | - return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' ); |
|
| 55 | - |
|
| 56 | - } // End paid_courses() |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * featured_courses function. |
|
| 61 | - * |
|
| 62 | - * @access public |
|
| 63 | - * @param mixed $atts |
|
| 64 | - * @param mixed $content (default: null) |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public static function featured_courses( $atts, $content = null ) { |
|
| 68 | - |
|
| 69 | - return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' ); |
|
| 13 | + /** |
|
| 14 | + * Add the legacy shortcodes to WordPress |
|
| 15 | + * |
|
| 16 | + * @since 1.9.0 |
|
| 17 | + */ |
|
| 18 | + public static function init(){ |
|
| 19 | + |
|
| 20 | + add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); |
|
| 21 | + add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); |
|
| 22 | + add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); |
|
| 23 | + add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); |
|
| 24 | + add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); |
|
| 25 | + add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); |
|
| 26 | + |
|
| 27 | + } |
|
| 28 | + /** |
|
| 29 | + * all_courses shortcode output function. |
|
| 30 | + * |
|
| 31 | + * The function should only be called indirectly through do_shortcode() |
|
| 32 | + * |
|
| 33 | + * @access public |
|
| 34 | + * @param mixed $atts |
|
| 35 | + * @param mixed $content (default: null) |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public static function all_courses( $atts, $content = null ) { |
|
| 39 | + |
|
| 40 | + return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title |
|
| 41 | + |
|
| 42 | + } // all_courses() |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * paid_courses function. |
|
| 46 | + * |
|
| 47 | + * @access public |
|
| 48 | + * @param mixed $atts |
|
| 49 | + * @param mixed $content (default: null) |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | + public static function paid_courses( $atts, $content = null ) { |
|
| 53 | + |
|
| 54 | + return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' ); |
|
| 55 | + |
|
| 56 | + } // End paid_courses() |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * featured_courses function. |
|
| 61 | + * |
|
| 62 | + * @access public |
|
| 63 | + * @param mixed $atts |
|
| 64 | + * @param mixed $content (default: null) |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public static function featured_courses( $atts, $content = null ) { |
|
| 68 | + |
|
| 69 | + return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' ); |
|
| 70 | 70 | |
| 71 | - } // End featured_courses() |
|
| 71 | + } // End featured_courses() |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * shortcode_free_courses function. |
|
| 75 | - * |
|
| 76 | - * @access public |
|
| 77 | - * @param mixed $atts |
|
| 78 | - * @param mixed $content (default: null) |
|
| 79 | - * @return string |
|
| 80 | - */ |
|
| 81 | - public static function free_courses( $atts, $content = null ) { |
|
| 73 | + /** |
|
| 74 | + * shortcode_free_courses function. |
|
| 75 | + * |
|
| 76 | + * @access public |
|
| 77 | + * @param mixed $atts |
|
| 78 | + * @param mixed $content (default: null) |
|
| 79 | + * @return string |
|
| 80 | + */ |
|
| 81 | + public static function free_courses( $atts, $content = null ) { |
|
| 82 | 82 | |
| 83 | - return self::generate_shortcode_courses( 'Free Courses', 'freecourses' ); |
|
| 83 | + return self::generate_shortcode_courses( 'Free Courses', 'freecourses' ); |
|
| 84 | 84 | |
| 85 | - } // End free_courses() |
|
| 85 | + } // End free_courses() |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * shortcode_new_courses function. |
|
| 89 | - * |
|
| 90 | - * @access public |
|
| 91 | - * @param mixed $atts |
|
| 92 | - * @param mixed $content (default: null) |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public static function new_courses( $atts, $content = null ) { |
|
| 87 | + /** |
|
| 88 | + * shortcode_new_courses function. |
|
| 89 | + * |
|
| 90 | + * @access public |
|
| 91 | + * @param mixed $atts |
|
| 92 | + * @param mixed $content (default: null) |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public static function new_courses( $atts, $content = null ) { |
|
| 96 | 96 | |
| 97 | - return self::generate_shortcode_courses( 'New Courses', 'newcourses' ); |
|
| 97 | + return self::generate_shortcode_courses( 'New Courses', 'newcourses' ); |
|
| 98 | 98 | |
| 99 | - } // End new_courses() |
|
| 99 | + } // End new_courses() |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Generate courses adding a title. |
|
| 103 | - * |
|
| 104 | - * @since 1.9.0 |
|
| 105 | - * |
|
| 106 | - * @param $title |
|
| 107 | - * @param $shortcode_specific_override |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public static function generate_shortcode_courses( $title , $shortcode_specific_override ){ |
|
| 101 | + /** |
|
| 102 | + * Generate courses adding a title. |
|
| 103 | + * |
|
| 104 | + * @since 1.9.0 |
|
| 105 | + * |
|
| 106 | + * @param $title |
|
| 107 | + * @param $shortcode_specific_override |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public static function generate_shortcode_courses( $title , $shortcode_specific_override ){ |
|
| 111 | 111 | |
| 112 | - global $shortcode_override, $posts_array; |
|
| 112 | + global $shortcode_override, $posts_array; |
|
| 113 | 113 | |
| 114 | - $shortcode_override = $shortcode_specific_override; |
|
| 114 | + $shortcode_override = $shortcode_specific_override; |
|
| 115 | 115 | |
| 116 | - // do not show this short code if there is a shortcode int he url and |
|
| 117 | - // this specific shortcode is not the one requested in the ur. |
|
| 118 | - $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
| 119 | - if( ! empty( $specific_shortcode_requested) && |
|
| 120 | - $specific_shortcode_requested != $shortcode_override ){ |
|
| 116 | + // do not show this short code if there is a shortcode int he url and |
|
| 117 | + // this specific shortcode is not the one requested in the ur. |
|
| 118 | + $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
| 119 | + if( ! empty( $specific_shortcode_requested) && |
|
| 120 | + $specific_shortcode_requested != $shortcode_override ){ |
|
| 121 | 121 | |
| 122 | - return ''; |
|
| 122 | + return ''; |
|
| 123 | 123 | |
| 124 | - } |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - // loop and get all courses html |
|
| 127 | - ob_start(); |
|
| 128 | - self::initialise_legacy_course_loop(); |
|
| 129 | - $courses = ob_get_clean(); |
|
| 126 | + // loop and get all courses html |
|
| 127 | + ob_start(); |
|
| 128 | + self::initialise_legacy_course_loop(); |
|
| 129 | + $courses = ob_get_clean(); |
|
| 130 | 130 | |
| 131 | - $content = ''; |
|
| 132 | - if( count( $posts_array ) > 0 ){ |
|
| 131 | + $content = ''; |
|
| 132 | + if( count( $posts_array ) > 0 ){ |
|
| 133 | 133 | |
| 134 | - $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; |
|
| 135 | - $before .= '<section id="main-course" class="course-container">'; |
|
| 134 | + $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; |
|
| 135 | + $before .= '<section id="main-course" class="course-container">'; |
|
| 136 | 136 | |
| 137 | - $after = '</section>'; |
|
| 137 | + $after = '</section>'; |
|
| 138 | 138 | |
| 139 | - //assemble |
|
| 140 | - $content = $before . $courses . $after; |
|
| 139 | + //assemble |
|
| 140 | + $content = $before . $courses . $after; |
|
| 141 | 141 | |
| 142 | - } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - return $content; |
|
| 144 | + return $content; |
|
| 145 | 145 | |
| 146 | - }// end generate_shortcode_courses |
|
| 146 | + }// end generate_shortcode_courses |
|
| 147 | 147 | |
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * user_courses function. |
|
| 151 | - * |
|
| 152 | - * @access public |
|
| 153 | - * @param mixed $atts |
|
| 154 | - * @param mixed $content (default: null) |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public static function user_courses( $atts, $content = null ) { |
|
| 158 | - global $shortcode_override; |
|
| 159 | - extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); |
|
| 149 | + /** |
|
| 150 | + * user_courses function. |
|
| 151 | + * |
|
| 152 | + * @access public |
|
| 153 | + * @param mixed $atts |
|
| 154 | + * @param mixed $content (default: null) |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public static function user_courses( $atts, $content = null ) { |
|
| 158 | + global $shortcode_override; |
|
| 159 | + extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); |
|
| 160 | 160 | |
| 161 | - $shortcode_override = 'usercourses'; |
|
| 161 | + $shortcode_override = 'usercourses'; |
|
| 162 | 162 | |
| 163 | - ob_start(); |
|
| 163 | + ob_start(); |
|
| 164 | 164 | |
| 165 | - if( is_user_logged_in() ){ |
|
| 165 | + if( is_user_logged_in() ){ |
|
| 166 | 166 | |
| 167 | - Sensei_Templates::get_template( 'user/my-courses.php' ); |
|
| 167 | + Sensei_Templates::get_template( 'user/my-courses.php' ); |
|
| 168 | 168 | |
| 169 | - }else{ |
|
| 169 | + }else{ |
|
| 170 | 170 | |
| 171 | - Sensei()->frontend->sensei_login_form(); |
|
| 171 | + Sensei()->frontend->sensei_login_form(); |
|
| 172 | 172 | |
| 173 | - } |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - $content = ob_get_clean(); |
|
| 176 | - return $content; |
|
| 175 | + $content = ob_get_clean(); |
|
| 176 | + return $content; |
|
| 177 | 177 | |
| 178 | - } // End user_courses() |
|
| 178 | + } // End user_courses() |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * This function is simply to honor the legacy |
|
| 182 | - * loop-course.php for the old shortcodes. |
|
| 183 | - * @since 1.9.0 |
|
| 184 | - */ |
|
| 185 | - public static function initialise_legacy_course_loop(){ |
|
| 180 | + /** |
|
| 181 | + * This function is simply to honor the legacy |
|
| 182 | + * loop-course.php for the old shortcodes. |
|
| 183 | + * @since 1.9.0 |
|
| 184 | + */ |
|
| 185 | + public static function initialise_legacy_course_loop(){ |
|
| 186 | 186 | |
| 187 | - global $post, $wp_query, $shortcode_override, $course_excludes; |
|
| 187 | + global $post, $wp_query, $shortcode_override, $course_excludes; |
|
| 188 | 188 | |
| 189 | - // Handle Query Type |
|
| 190 | - $query_type = ''; |
|
| 189 | + // Handle Query Type |
|
| 190 | + $query_type = ''; |
|
| 191 | 191 | |
| 192 | - if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { |
|
| 193 | - $query_type = esc_html( $_GET[ 'action' ] ); |
|
| 194 | - } // End If Statement |
|
| 192 | + if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { |
|
| 193 | + $query_type = esc_html( $_GET[ 'action' ] ); |
|
| 194 | + } // End If Statement |
|
| 195 | 195 | |
| 196 | - if ( '' != $shortcode_override ) { |
|
| 197 | - $query_type = $shortcode_override; |
|
| 198 | - } // End If Statement |
|
| 196 | + if ( '' != $shortcode_override ) { |
|
| 197 | + $query_type = $shortcode_override; |
|
| 198 | + } // End If Statement |
|
| 199 | 199 | |
| 200 | - if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } |
|
| 200 | + if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } |
|
| 201 | 201 | |
| 202 | - // Check that query returns results |
|
| 203 | - // Handle Pagination |
|
| 204 | - $paged = $wp_query->get( 'paged' ); |
|
| 205 | - $paged = empty( $paged ) ? 1 : $paged; |
|
| 202 | + // Check that query returns results |
|
| 203 | + // Handle Pagination |
|
| 204 | + $paged = $wp_query->get( 'paged' ); |
|
| 205 | + $paged = empty( $paged ) ? 1 : $paged; |
|
| 206 | 206 | |
| 207 | 207 | |
| 208 | - // Check for pagination settings |
|
| 209 | - if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
|
| 208 | + // Check for pagination settings |
|
| 209 | + if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
|
| 210 | 210 | |
| 211 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 211 | + $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 212 | 212 | |
| 213 | - } else { |
|
| 213 | + } else { |
|
| 214 | 214 | |
| 215 | - $amount = $wp_query->get( 'posts_per_page' ); |
|
| 215 | + $amount = $wp_query->get( 'posts_per_page' ); |
|
| 216 | 216 | |
| 217 | - } // End If Statement |
|
| 217 | + } // End If Statement |
|
| 218 | 218 | |
| 219 | - // This is not a paginated page (or it's simply the first page of a paginated page/post) |
|
| 219 | + // This is not a paginated page (or it's simply the first page of a paginated page/post) |
|
| 220 | 220 | |
| 221 | - global $posts_array; |
|
| 222 | - $course_includes = array(); |
|
| 221 | + global $posts_array; |
|
| 222 | + $course_includes = array(); |
|
| 223 | 223 | |
| 224 | - $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); |
|
| 225 | - $course_query = new WP_Query( $query_args ); |
|
| 226 | - $posts_array = $course_query->get_posts(); |
|
| 224 | + $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); |
|
| 225 | + $course_query = new WP_Query( $query_args ); |
|
| 226 | + $posts_array = $course_query->get_posts(); |
|
| 227 | 227 | |
| 228 | - // output the courses |
|
| 229 | - if( ! empty( $posts_array ) ) { |
|
| 228 | + // output the courses |
|
| 229 | + if( ! empty( $posts_array ) ) { |
|
| 230 | 230 | |
| 231 | - //output all courses for current query |
|
| 232 | - self::loop_courses( $course_query, $amount ); |
|
| 231 | + //output all courses for current query |
|
| 232 | + self::loop_courses( $course_query, $amount ); |
|
| 233 | 233 | |
| 234 | - } |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - } |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * Loop through courses in the query and output the infomration needed |
|
| 240 | - * |
|
| 241 | - * @since 1.9.0 |
|
| 242 | - * |
|
| 243 | - * @param WP_Query $course_query |
|
| 244 | - */ |
|
| 245 | - public static function loop_courses( $course_query, $amount ){ |
|
| 238 | + /** |
|
| 239 | + * Loop through courses in the query and output the infomration needed |
|
| 240 | + * |
|
| 241 | + * @since 1.9.0 |
|
| 242 | + * |
|
| 243 | + * @param WP_Query $course_query |
|
| 244 | + */ |
|
| 245 | + public static function loop_courses( $course_query, $amount ){ |
|
| 246 | 246 | |
| 247 | - global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; |
|
| 247 | + global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; |
|
| 248 | 248 | |
| 249 | - if ( count( $course_query->get_posts() ) > 0 ) { |
|
| 249 | + if ( count( $course_query->get_posts() ) > 0 ) { |
|
| 250 | 250 | |
| 251 | - do_action( 'sensei_course_archive_header', $shortcode_override ); |
|
| 251 | + do_action( 'sensei_course_archive_header', $shortcode_override ); |
|
| 252 | 252 | |
| 253 | - foreach ( $course_query->get_posts() as $course){ |
|
| 253 | + foreach ( $course_query->get_posts() as $course){ |
|
| 254 | 254 | |
| 255 | - // Make sure the other loops dont include the same post twice! |
|
| 256 | - array_push( $course_excludes, $course->ID ); |
|
| 255 | + // Make sure the other loops dont include the same post twice! |
|
| 256 | + array_push( $course_excludes, $course->ID ); |
|
| 257 | 257 | |
| 258 | - // output the course markup |
|
| 259 | - self::the_course( $course->ID ); |
|
| 258 | + // output the course markup |
|
| 259 | + self::the_course( $course->ID ); |
|
| 260 | 260 | |
| 261 | - } // End For Loop |
|
| 261 | + } // End For Loop |
|
| 262 | 262 | |
| 263 | - // More and Prev links |
|
| 264 | - $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); |
|
| 265 | - $posts_array = $posts_array_query->get_posts(); |
|
| 266 | - $max_pages = $course_query->found_posts / $amount; |
|
| 267 | - if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { |
|
| 263 | + // More and Prev links |
|
| 264 | + $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); |
|
| 265 | + $posts_array = $posts_array_query->get_posts(); |
|
| 266 | + $max_pages = $course_query->found_posts / $amount; |
|
| 267 | + if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { |
|
| 268 | 268 | |
| 269 | - switch( $shortcode_override ){ |
|
| 270 | - case 'paidcourses': |
|
| 271 | - $filter = 'paid'; |
|
| 272 | - break; |
|
| 273 | - case 'featuredcourses': |
|
| 274 | - $filter = 'featured'; |
|
| 275 | - break; |
|
| 276 | - case 'freecourses': |
|
| 277 | - $filter = 'free'; |
|
| 278 | - break; |
|
| 279 | - default: |
|
| 280 | - $filter = ''; |
|
| 281 | - break; |
|
| 282 | - } |
|
| 269 | + switch( $shortcode_override ){ |
|
| 270 | + case 'paidcourses': |
|
| 271 | + $filter = 'paid'; |
|
| 272 | + break; |
|
| 273 | + case 'featuredcourses': |
|
| 274 | + $filter = 'featured'; |
|
| 275 | + break; |
|
| 276 | + case 'freecourses': |
|
| 277 | + $filter = 'free'; |
|
| 278 | + break; |
|
| 279 | + default: |
|
| 280 | + $filter = ''; |
|
| 281 | + break; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - $quer_args = array(); |
|
| 285 | - $quer_args[ 'paged' ] = '2'; |
|
| 286 | - if( !empty( $filter ) ){ |
|
| 287 | - $quer_args[ 'course_filter' ] = $filter; |
|
| 288 | - } |
|
| 284 | + $quer_args = array(); |
|
| 285 | + $quer_args[ 'paged' ] = '2'; |
|
| 286 | + if( !empty( $filter ) ){ |
|
| 287 | + $quer_args[ 'course_filter' ] = $filter; |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - $course_pagination_link = get_post_type_archive_link( 'course' ); |
|
| 291 | - $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); |
|
| 292 | - $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); |
|
| 290 | + $course_pagination_link = get_post_type_archive_link( 'course' ); |
|
| 291 | + $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); |
|
| 292 | + $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); |
|
| 293 | 293 | |
| 294 | - // next/more |
|
| 295 | - $html = '<div class="navigation"><div class="nav-next">'; |
|
| 296 | - $html .= '<a href="' . $more_link_url . '">'; |
|
| 297 | - $html .= $more_link_text; |
|
| 298 | - $html .= '<span class="meta-nav"></span></a></div>'; |
|
| 294 | + // next/more |
|
| 295 | + $html = '<div class="navigation"><div class="nav-next">'; |
|
| 296 | + $html .= '<a href="' . $more_link_url . '">'; |
|
| 297 | + $html .= $more_link_text; |
|
| 298 | + $html .= '<span class="meta-nav"></span></a></div>'; |
|
| 299 | 299 | |
| 300 | - echo apply_filters( 'course_archive_next_link', $html ); |
|
| 300 | + echo apply_filters( 'course_archive_next_link', $html ); |
|
| 301 | 301 | |
| 302 | - } // End If Statement |
|
| 302 | + } // End If Statement |
|
| 303 | 303 | |
| 304 | - } // End If Statement |
|
| 305 | - } |
|
| 304 | + } // End If Statement |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - /** |
|
| 308 | - * Print a single course markup |
|
| 309 | - * |
|
| 310 | - * @param $course_id |
|
| 311 | - */ |
|
| 312 | - public static function the_course( $course_id ){ |
|
| 307 | + /** |
|
| 308 | + * Print a single course markup |
|
| 309 | + * |
|
| 310 | + * @param $course_id |
|
| 311 | + */ |
|
| 312 | + public static function the_course( $course_id ){ |
|
| 313 | 313 | |
| 314 | - // Get meta data |
|
| 315 | - $course = get_post( $course_id ); |
|
| 316 | - $user_info = get_userdata( absint( $course->post_author ) ); |
|
| 317 | - $author_link = get_author_posts_url( absint( $course->post_author ) ); |
|
| 318 | - $author_display_name = $user_info->display_name; |
|
| 319 | - $author_id = $course->post_author; |
|
| 320 | - $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); |
|
| 321 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); |
|
| 322 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 323 | - ?> |
|
| 314 | + // Get meta data |
|
| 315 | + $course = get_post( $course_id ); |
|
| 316 | + $user_info = get_userdata( absint( $course->post_author ) ); |
|
| 317 | + $author_link = get_author_posts_url( absint( $course->post_author ) ); |
|
| 318 | + $author_display_name = $user_info->display_name; |
|
| 319 | + $author_id = $course->post_author; |
|
| 320 | + $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); |
|
| 321 | + $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); |
|
| 322 | + $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 323 | + ?> |
|
| 324 | 324 | |
| 325 | 325 | <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>"> |
| 326 | 326 | <?php |
| 327 | - // so that legacy shortcodes work with thir party plugins that wants to hook in |
|
| 328 | - do_action('sensei_course_content_before',$course ); |
|
| 329 | - ?> |
|
| 327 | + // so that legacy shortcodes work with thir party plugins that wants to hook in |
|
| 328 | + do_action('sensei_course_content_before',$course ); |
|
| 329 | + ?> |
|
| 330 | 330 | <div class="course-content"> |
| 331 | 331 | |
| 332 | 332 | <?php Sensei()->course->course_image($course_id); ?> |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | </p> |
| 363 | 363 | |
| 364 | 364 | <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
| 365 | - $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> |
|
| 365 | + $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> |
|
| 366 | 366 | <p class="sensei-free-lessons"> |
| 367 | 367 | <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?> |
| 368 | 368 | </a> - <?php echo $preview_lessons; ?> |
@@ -373,15 +373,15 @@ discard block |
||
| 373 | 373 | |
| 374 | 374 | </div> |
| 375 | 375 | <?php |
| 376 | - // so that legacy shortcodes work with thir party plugins that wants to hook in |
|
| 377 | - do_action('sensei_course_content_after', $course); |
|
| 378 | - ?> |
|
| 376 | + // so that legacy shortcodes work with thir party plugins that wants to hook in |
|
| 377 | + do_action('sensei_course_content_after', $course); |
|
| 378 | + ?> |
|
| 379 | 379 | |
| 380 | 380 | </article> |
| 381 | 381 | |
| 382 | 382 | <?php |
| 383 | 383 | |
| 384 | 384 | |
| 385 | - } // end the_course |
|
| 385 | + } // end the_course |
|
| 386 | 386 | |
| 387 | 387 | }// end class legacy shortcodes |
| 388 | 388 | \ No newline at end of file |
@@ -15,14 +15,14 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @since 1.9.0 |
| 17 | 17 | */ |
| 18 | - public static function init(){ |
|
| 18 | + public static function init() { |
|
| 19 | 19 | |
| 20 | - add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); |
|
| 21 | - add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); |
|
| 22 | - add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); |
|
| 23 | - add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); |
|
| 24 | - add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); |
|
| 25 | - add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); |
|
| 20 | + add_shortcode('allcourses', array(__CLASS__, 'all_courses')); |
|
| 21 | + add_shortcode('newcourses', array(__CLASS__, 'new_courses')); |
|
| 22 | + add_shortcode('featuredcourses', array(__CLASS__, 'featured_courses')); |
|
| 23 | + add_shortcode('freecourses', array(__CLASS__, 'free_courses')); |
|
| 24 | + add_shortcode('paidcourses', array(__CLASS__, 'paid_courses')); |
|
| 25 | + add_shortcode('usercourses', array(__CLASS__, 'user_courses')); |
|
| 26 | 26 | |
| 27 | 27 | } |
| 28 | 28 | /** |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | * @param mixed $content (default: null) |
| 36 | 36 | * @return string |
| 37 | 37 | */ |
| 38 | - public static function all_courses( $atts, $content = null ) { |
|
| 38 | + public static function all_courses($atts, $content = null) { |
|
| 39 | 39 | |
| 40 | - return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title |
|
| 40 | + return self::generate_shortcode_courses('', 'allcourses'); // all courses but no title |
|
| 41 | 41 | |
| 42 | 42 | } // all_courses() |
| 43 | 43 | |
@@ -49,9 +49,9 @@ discard block |
||
| 49 | 49 | * @param mixed $content (default: null) |
| 50 | 50 | * @return string |
| 51 | 51 | */ |
| 52 | - public static function paid_courses( $atts, $content = null ) { |
|
| 52 | + public static function paid_courses($atts, $content = null) { |
|
| 53 | 53 | |
| 54 | - return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' ); |
|
| 54 | + return self::generate_shortcode_courses('Paid Courses', 'paidcourses'); |
|
| 55 | 55 | |
| 56 | 56 | } // End paid_courses() |
| 57 | 57 | |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | * @param mixed $content (default: null) |
| 65 | 65 | * @return string |
| 66 | 66 | */ |
| 67 | - public static function featured_courses( $atts, $content = null ) { |
|
| 67 | + public static function featured_courses($atts, $content = null) { |
|
| 68 | 68 | |
| 69 | - return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' ); |
|
| 69 | + return self::generate_shortcode_courses('Featured Courses', 'featuredcourses'); |
|
| 70 | 70 | |
| 71 | 71 | } // End featured_courses() |
| 72 | 72 | |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * @param mixed $content (default: null) |
| 79 | 79 | * @return string |
| 80 | 80 | */ |
| 81 | - public static function free_courses( $atts, $content = null ) { |
|
| 81 | + public static function free_courses($atts, $content = null) { |
|
| 82 | 82 | |
| 83 | - return self::generate_shortcode_courses( 'Free Courses', 'freecourses' ); |
|
| 83 | + return self::generate_shortcode_courses('Free Courses', 'freecourses'); |
|
| 84 | 84 | |
| 85 | 85 | } // End free_courses() |
| 86 | 86 | |
@@ -92,9 +92,9 @@ discard block |
||
| 92 | 92 | * @param mixed $content (default: null) |
| 93 | 93 | * @return string |
| 94 | 94 | */ |
| 95 | - public static function new_courses( $atts, $content = null ) { |
|
| 95 | + public static function new_courses($atts, $content = null) { |
|
| 96 | 96 | |
| 97 | - return self::generate_shortcode_courses( 'New Courses', 'newcourses' ); |
|
| 97 | + return self::generate_shortcode_courses('New Courses', 'newcourses'); |
|
| 98 | 98 | |
| 99 | 99 | } // End new_courses() |
| 100 | 100 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @param $shortcode_specific_override |
| 108 | 108 | * @return string |
| 109 | 109 | */ |
| 110 | - public static function generate_shortcode_courses( $title , $shortcode_specific_override ){ |
|
| 110 | + public static function generate_shortcode_courses($title, $shortcode_specific_override) { |
|
| 111 | 111 | |
| 112 | 112 | global $shortcode_override, $posts_array; |
| 113 | 113 | |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | // do not show this short code if there is a shortcode int he url and |
| 117 | 117 | // this specific shortcode is not the one requested in the ur. |
| 118 | - $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
| 119 | - if( ! empty( $specific_shortcode_requested) && |
|
| 120 | - $specific_shortcode_requested != $shortcode_override ){ |
|
| 118 | + $specific_shortcode_requested = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : ''; |
|
| 119 | + if ( ! empty($specific_shortcode_requested) && |
|
| 120 | + $specific_shortcode_requested != $shortcode_override) { |
|
| 121 | 121 | |
| 122 | 122 | return ''; |
| 123 | 123 | |
@@ -129,15 +129,15 @@ discard block |
||
| 129 | 129 | $courses = ob_get_clean(); |
| 130 | 130 | |
| 131 | 131 | $content = ''; |
| 132 | - if( count( $posts_array ) > 0 ){ |
|
| 132 | + if (count($posts_array) > 0) { |
|
| 133 | 133 | |
| 134 | - $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; |
|
| 134 | + $before = empty($title) ? '' : '<header class="archive-header"><h2>'.$title.'</h2></header>'; |
|
| 135 | 135 | $before .= '<section id="main-course" class="course-container">'; |
| 136 | 136 | |
| 137 | 137 | $after = '</section>'; |
| 138 | 138 | |
| 139 | 139 | //assemble |
| 140 | - $content = $before . $courses . $after; |
|
| 140 | + $content = $before.$courses.$after; |
|
| 141 | 141 | |
| 142 | 142 | } |
| 143 | 143 | |
@@ -154,19 +154,19 @@ discard block |
||
| 154 | 154 | * @param mixed $content (default: null) |
| 155 | 155 | * @return string |
| 156 | 156 | */ |
| 157 | - public static function user_courses( $atts, $content = null ) { |
|
| 157 | + public static function user_courses($atts, $content = null) { |
|
| 158 | 158 | global $shortcode_override; |
| 159 | - extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); |
|
| 159 | + extract(shortcode_atts(array('amount' => 0), $atts)); |
|
| 160 | 160 | |
| 161 | 161 | $shortcode_override = 'usercourses'; |
| 162 | 162 | |
| 163 | 163 | ob_start(); |
| 164 | 164 | |
| 165 | - if( is_user_logged_in() ){ |
|
| 165 | + if (is_user_logged_in()) { |
|
| 166 | 166 | |
| 167 | - Sensei_Templates::get_template( 'user/my-courses.php' ); |
|
| 167 | + Sensei_Templates::get_template('user/my-courses.php'); |
|
| 168 | 168 | |
| 169 | - }else{ |
|
| 169 | + } else { |
|
| 170 | 170 | |
| 171 | 171 | Sensei()->frontend->sensei_login_form(); |
| 172 | 172 | |
@@ -182,54 +182,54 @@ discard block |
||
| 182 | 182 | * loop-course.php for the old shortcodes. |
| 183 | 183 | * @since 1.9.0 |
| 184 | 184 | */ |
| 185 | - public static function initialise_legacy_course_loop(){ |
|
| 185 | + public static function initialise_legacy_course_loop() { |
|
| 186 | 186 | |
| 187 | 187 | global $post, $wp_query, $shortcode_override, $course_excludes; |
| 188 | 188 | |
| 189 | 189 | // Handle Query Type |
| 190 | 190 | $query_type = ''; |
| 191 | 191 | |
| 192 | - if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { |
|
| 193 | - $query_type = esc_html( $_GET[ 'action' ] ); |
|
| 192 | + if (isset($_GET['action']) && ('' != esc_html($_GET['action']))) { |
|
| 193 | + $query_type = esc_html($_GET['action']); |
|
| 194 | 194 | } // End If Statement |
| 195 | 195 | |
| 196 | - if ( '' != $shortcode_override ) { |
|
| 196 | + if ('' != $shortcode_override) { |
|
| 197 | 197 | $query_type = $shortcode_override; |
| 198 | 198 | } // End If Statement |
| 199 | 199 | |
| 200 | - if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } |
|
| 200 | + if ( ! is_array($course_excludes)) { $course_excludes = array(); } |
|
| 201 | 201 | |
| 202 | 202 | // Check that query returns results |
| 203 | 203 | // Handle Pagination |
| 204 | - $paged = $wp_query->get( 'paged' ); |
|
| 205 | - $paged = empty( $paged ) ? 1 : $paged; |
|
| 204 | + $paged = $wp_query->get('paged'); |
|
| 205 | + $paged = empty($paged) ? 1 : $paged; |
|
| 206 | 206 | |
| 207 | 207 | |
| 208 | 208 | // Check for pagination settings |
| 209 | - if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
|
| 209 | + if (isset(Sensei()->settings->settings['course_archive_amount']) && (0 < absint(Sensei()->settings->settings['course_archive_amount']))) { |
|
| 210 | 210 | |
| 211 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 211 | + $amount = absint(Sensei()->settings->settings['course_archive_amount']); |
|
| 212 | 212 | |
| 213 | 213 | } else { |
| 214 | 214 | |
| 215 | - $amount = $wp_query->get( 'posts_per_page' ); |
|
| 215 | + $amount = $wp_query->get('posts_per_page'); |
|
| 216 | 216 | |
| 217 | 217 | } // End If Statement |
| 218 | 218 | |
| 219 | 219 | // This is not a paginated page (or it's simply the first page of a paginated page/post) |
| 220 | 220 | |
| 221 | 221 | global $posts_array; |
| 222 | - $course_includes = array(); |
|
| 222 | + $course_includes = array(); |
|
| 223 | 223 | |
| 224 | - $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); |
|
| 225 | - $course_query = new WP_Query( $query_args ); |
|
| 224 | + $query_args = Sensei()->course->get_archive_query_args($shortcode_override, $amount, $course_includes, $course_excludes); |
|
| 225 | + $course_query = new WP_Query($query_args); |
|
| 226 | 226 | $posts_array = $course_query->get_posts(); |
| 227 | 227 | |
| 228 | 228 | // output the courses |
| 229 | - if( ! empty( $posts_array ) ) { |
|
| 229 | + if ( ! empty($posts_array)) { |
|
| 230 | 230 | |
| 231 | 231 | //output all courses for current query |
| 232 | - self::loop_courses( $course_query, $amount ); |
|
| 232 | + self::loop_courses($course_query, $amount); |
|
| 233 | 233 | |
| 234 | 234 | } |
| 235 | 235 | |
@@ -242,31 +242,31 @@ discard block |
||
| 242 | 242 | * |
| 243 | 243 | * @param WP_Query $course_query |
| 244 | 244 | */ |
| 245 | - public static function loop_courses( $course_query, $amount ){ |
|
| 245 | + public static function loop_courses($course_query, $amount) { |
|
| 246 | 246 | |
| 247 | 247 | global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; |
| 248 | 248 | |
| 249 | - if ( count( $course_query->get_posts() ) > 0 ) { |
|
| 249 | + if (count($course_query->get_posts()) > 0) { |
|
| 250 | 250 | |
| 251 | - do_action( 'sensei_course_archive_header', $shortcode_override ); |
|
| 251 | + do_action('sensei_course_archive_header', $shortcode_override); |
|
| 252 | 252 | |
| 253 | - foreach ( $course_query->get_posts() as $course){ |
|
| 253 | + foreach ($course_query->get_posts() as $course) { |
|
| 254 | 254 | |
| 255 | 255 | // Make sure the other loops dont include the same post twice! |
| 256 | - array_push( $course_excludes, $course->ID ); |
|
| 256 | + array_push($course_excludes, $course->ID); |
|
| 257 | 257 | |
| 258 | 258 | // output the course markup |
| 259 | - self::the_course( $course->ID ); |
|
| 259 | + self::the_course($course->ID); |
|
| 260 | 260 | |
| 261 | 261 | } // End For Loop |
| 262 | 262 | |
| 263 | 263 | // More and Prev links |
| 264 | - $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); |
|
| 264 | + $posts_array_query = new WP_Query(Sensei()->course->course_query($shortcode_override, $amount, $course_includes, $course_excludes)); |
|
| 265 | 265 | $posts_array = $posts_array_query->get_posts(); |
| 266 | 266 | $max_pages = $course_query->found_posts / $amount; |
| 267 | - if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { |
|
| 267 | + if ('' != $shortcode_override && ($max_pages > $course_query->get('paged'))) { |
|
| 268 | 268 | |
| 269 | - switch( $shortcode_override ){ |
|
| 269 | + switch ($shortcode_override) { |
|
| 270 | 270 | case 'paidcourses': |
| 271 | 271 | $filter = 'paid'; |
| 272 | 272 | break; |
@@ -282,22 +282,22 @@ discard block |
||
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | $quer_args = array(); |
| 285 | - $quer_args[ 'paged' ] = '2'; |
|
| 286 | - if( !empty( $filter ) ){ |
|
| 287 | - $quer_args[ 'course_filter' ] = $filter; |
|
| 285 | + $quer_args['paged'] = '2'; |
|
| 286 | + if ( ! empty($filter)) { |
|
| 287 | + $quer_args['course_filter'] = $filter; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - $course_pagination_link = get_post_type_archive_link( 'course' ); |
|
| 291 | - $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); |
|
| 292 | - $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); |
|
| 290 | + $course_pagination_link = get_post_type_archive_link('course'); |
|
| 291 | + $more_link_text = esc_html(Sensei()->settings->settings['course_archive_more_link_text']); |
|
| 292 | + $more_link_url = esc_url(add_query_arg($quer_args, $course_pagination_link)); |
|
| 293 | 293 | |
| 294 | 294 | // next/more |
| 295 | 295 | $html = '<div class="navigation"><div class="nav-next">'; |
| 296 | - $html .= '<a href="' . $more_link_url . '">'; |
|
| 296 | + $html .= '<a href="'.$more_link_url.'">'; |
|
| 297 | 297 | $html .= $more_link_text; |
| 298 | 298 | $html .= '<span class="meta-nav"></span></a></div>'; |
| 299 | 299 | |
| 300 | - echo apply_filters( 'course_archive_next_link', $html ); |
|
| 300 | + echo apply_filters('course_archive_next_link', $html); |
|
| 301 | 301 | |
| 302 | 302 | } // End If Statement |
| 303 | 303 | |
@@ -309,23 +309,23 @@ discard block |
||
| 309 | 309 | * |
| 310 | 310 | * @param $course_id |
| 311 | 311 | */ |
| 312 | - public static function the_course( $course_id ){ |
|
| 312 | + public static function the_course($course_id) { |
|
| 313 | 313 | |
| 314 | 314 | // Get meta data |
| 315 | - $course = get_post( $course_id ); |
|
| 316 | - $user_info = get_userdata( absint( $course->post_author ) ); |
|
| 317 | - $author_link = get_author_posts_url( absint( $course->post_author ) ); |
|
| 315 | + $course = get_post($course_id); |
|
| 316 | + $user_info = get_userdata(absint($course->post_author)); |
|
| 317 | + $author_link = get_author_posts_url(absint($course->post_author)); |
|
| 318 | 318 | $author_display_name = $user_info->display_name; |
| 319 | 319 | $author_id = $course->post_author; |
| 320 | - $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); |
|
| 321 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); |
|
| 322 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 320 | + $category_output = get_the_term_list($course_id, 'course-category', '', ', ', ''); |
|
| 321 | + $preview_lesson_count = intval(Sensei()->course->course_lesson_preview_count($course_id)); |
|
| 322 | + $is_user_taking_course = Sensei_Utils::user_started_course($course_id, get_current_user_id()); |
|
| 323 | 323 | ?> |
| 324 | 324 | |
| 325 | - <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>"> |
|
| 325 | + <article class="<?php echo esc_attr(join(' ', get_post_class(array('course', 'post'), $course_id))); ?>"> |
|
| 326 | 326 | <?php |
| 327 | 327 | // so that legacy shortcodes work with thir party plugins that wants to hook in |
| 328 | - do_action('sensei_course_content_before',$course ); |
|
| 328 | + do_action('sensei_course_content_before', $course); |
|
| 329 | 329 | ?> |
| 330 | 330 | <div class="course-content"> |
| 331 | 331 | |
@@ -341,19 +341,19 @@ discard block |
||
| 341 | 341 | |
| 342 | 342 | <p class="sensei-course-meta"> |
| 343 | 343 | |
| 344 | - <?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?> |
|
| 345 | - <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr( $author_display_name ); ?>"><?php echo esc_html( $author_display_name ); ?></a></span> |
|
| 344 | + <?php if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { ?> |
|
| 345 | + <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr($author_display_name); ?>"><?php echo esc_html($author_display_name); ?></a></span> |
|
| 346 | 346 | <?php } // End If Statement ?> |
| 347 | 347 | |
| 348 | 348 | <span class="course-lesson-count"> |
| 349 | - <?php echo Sensei()->course->course_lesson_count( $course_id ) . ' ' . __( 'Lessons', 'woothemes-sensei' ); ?> |
|
| 349 | + <?php echo Sensei()->course->course_lesson_count($course_id).' '.__('Lessons', 'woothemes-sensei'); ?> |
|
| 350 | 350 | </span> |
| 351 | 351 | |
| 352 | - <?php if ( '' != $category_output ) { ?> |
|
| 353 | - <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span> |
|
| 352 | + <?php if ('' != $category_output) { ?> |
|
| 353 | + <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span> |
|
| 354 | 354 | <?php } // End If Statement ?> |
| 355 | 355 | |
| 356 | - <?php sensei_simple_course_price( $course_id ); ?> |
|
| 356 | + <?php sensei_simple_course_price($course_id); ?> |
|
| 357 | 357 | |
| 358 | 358 | </p> |
| 359 | 359 | |
@@ -361,10 +361,10 @@ discard block |
||
| 361 | 361 | |
| 362 | 362 | </p> |
| 363 | 363 | |
| 364 | - <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
| 365 | - $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> |
|
| 364 | + <?php if (0 < $preview_lesson_count && ! $is_user_taking_course) { |
|
| 365 | + $preview_lessons = sprintf(__('(%d preview lessons)', 'woothemes-sensei'), $preview_lesson_count); ?> |
|
| 366 | 366 | <p class="sensei-free-lessons"> |
| 367 | - <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?> |
|
| 367 | + <a href="<?php echo get_permalink($course_id); ?>"><?php _e('Preview this course', 'woothemes-sensei') ?> |
|
| 368 | 368 | </a> - <?php echo $preview_lessons; ?> |
| 369 | 369 | </p> |
| 370 | 370 | <?php } ?> |
@@ -14,138 +14,138 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Shortcode_Unpurchased_Courses implements Sensei_Shortcode_Interface { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var WP_Query to help setup the query needed by the render method. |
|
| 19 | - */ |
|
| 20 | - protected $query; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @var string number of items to show on the current page |
|
| 24 | - * Default: all. |
|
| 25 | - */ |
|
| 26 | - protected $number; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var string ordery by course field |
|
| 30 | - * Default: date |
|
| 31 | - */ |
|
| 32 | - protected $orderby; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var string ASC or DESC |
|
| 36 | - * Default: 'DESC' |
|
| 37 | - */ |
|
| 38 | - protected $order; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Setup the shortcode object |
|
| 42 | - * |
|
| 43 | - * @since 1.9.0 |
|
| 44 | - * @param array $attributes |
|
| 45 | - * @param string $content |
|
| 46 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 47 | - */ |
|
| 48 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 49 | - |
|
| 50 | - if( !is_user_logged_in() ) { |
|
| 51 | - return; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - // set up all argument need for constructing the course query |
|
| 55 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 56 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 57 | - |
|
| 58 | - // set the default for menu_order to be ASC |
|
| 59 | - if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 60 | - |
|
| 61 | - $this->order = 'ASC'; |
|
| 62 | - |
|
| 63 | - }else{ |
|
| 64 | - |
|
| 65 | - // for everything else use the value passed or the default DESC |
|
| 66 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
|
| 67 | - |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - // setup the course query that will be used when rendering |
|
| 71 | - $this->setup_course_query(); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Sets up the object course query |
|
| 76 | - * that will be used int he render method. |
|
| 77 | - * |
|
| 78 | - * @since 1.9.0 |
|
| 79 | - */ |
|
| 80 | - protected function setup_course_query(){ |
|
| 81 | - |
|
| 82 | - // course query parameters to be used for all courses |
|
| 83 | - $query_args = array( |
|
| 84 | - 'post_type' => 'course', |
|
| 85 | - 'post_status' => 'publish', |
|
| 86 | - // the number specified by the user will be used later in this function |
|
| 87 | - 'posts_per_page' => 1000, |
|
| 88 | - 'orderby' => $this->orderby, |
|
| 89 | - 'order' => $this->order |
|
| 90 | - ); |
|
| 91 | - |
|
| 92 | - // get all the courses that has a product attached |
|
| 93 | - $all_courses_query = new WP_Query( $query_args ); |
|
| 94 | - |
|
| 95 | - $paid_courses_not_taken = array(); |
|
| 96 | - // look through all course and find the purchasable ones that user has not purchased |
|
| 97 | - foreach( $all_courses_query->posts as $course ){ |
|
| 98 | - |
|
| 99 | - // only keep the courses with a product including only courses that the user not taking |
|
| 100 | - $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true ); |
|
| 101 | - if( is_numeric( $course_product_id ) |
|
| 102 | - && |
|
| 103 | - ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id() ) |
|
| 104 | - ){ |
|
| 105 | - |
|
| 106 | - $paid_courses_not_taken[] = $course->ID; |
|
| 107 | - |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - } // end foreach |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - // setup the course query again and only use the course the user has not purchased. |
|
| 114 | - // this query will be loaded into the global WP_Query in the render function. |
|
| 115 | - $query_args['post__in'] = $paid_courses_not_taken; |
|
| 116 | - $query_args['posts_per_page'] = $this->number; |
|
| 117 | - $this->query = new WP_Query( $query_args ); |
|
| 118 | - |
|
| 119 | - }// end setup _course_query |
|
| 17 | + /** |
|
| 18 | + * @var WP_Query to help setup the query needed by the render method. |
|
| 19 | + */ |
|
| 20 | + protected $query; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @var string number of items to show on the current page |
|
| 24 | + * Default: all. |
|
| 25 | + */ |
|
| 26 | + protected $number; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var string ordery by course field |
|
| 30 | + * Default: date |
|
| 31 | + */ |
|
| 32 | + protected $orderby; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var string ASC or DESC |
|
| 36 | + * Default: 'DESC' |
|
| 37 | + */ |
|
| 38 | + protected $order; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Setup the shortcode object |
|
| 42 | + * |
|
| 43 | + * @since 1.9.0 |
|
| 44 | + * @param array $attributes |
|
| 45 | + * @param string $content |
|
| 46 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 47 | + */ |
|
| 48 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 49 | + |
|
| 50 | + if( !is_user_logged_in() ) { |
|
| 51 | + return; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + // set up all argument need for constructing the course query |
|
| 55 | + $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 56 | + $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 57 | + |
|
| 58 | + // set the default for menu_order to be ASC |
|
| 59 | + if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 60 | + |
|
| 61 | + $this->order = 'ASC'; |
|
| 62 | + |
|
| 63 | + }else{ |
|
| 64 | + |
|
| 65 | + // for everything else use the value passed or the default DESC |
|
| 66 | + $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
|
| 67 | + |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + // setup the course query that will be used when rendering |
|
| 71 | + $this->setup_course_query(); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Sets up the object course query |
|
| 76 | + * that will be used int he render method. |
|
| 77 | + * |
|
| 78 | + * @since 1.9.0 |
|
| 79 | + */ |
|
| 80 | + protected function setup_course_query(){ |
|
| 81 | + |
|
| 82 | + // course query parameters to be used for all courses |
|
| 83 | + $query_args = array( |
|
| 84 | + 'post_type' => 'course', |
|
| 85 | + 'post_status' => 'publish', |
|
| 86 | + // the number specified by the user will be used later in this function |
|
| 87 | + 'posts_per_page' => 1000, |
|
| 88 | + 'orderby' => $this->orderby, |
|
| 89 | + 'order' => $this->order |
|
| 90 | + ); |
|
| 91 | + |
|
| 92 | + // get all the courses that has a product attached |
|
| 93 | + $all_courses_query = new WP_Query( $query_args ); |
|
| 94 | + |
|
| 95 | + $paid_courses_not_taken = array(); |
|
| 96 | + // look through all course and find the purchasable ones that user has not purchased |
|
| 97 | + foreach( $all_courses_query->posts as $course ){ |
|
| 98 | + |
|
| 99 | + // only keep the courses with a product including only courses that the user not taking |
|
| 100 | + $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true ); |
|
| 101 | + if( is_numeric( $course_product_id ) |
|
| 102 | + && |
|
| 103 | + ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id() ) |
|
| 104 | + ){ |
|
| 105 | + |
|
| 106 | + $paid_courses_not_taken[] = $course->ID; |
|
| 107 | + |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + } // end foreach |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + // setup the course query again and only use the course the user has not purchased. |
|
| 114 | + // this query will be loaded into the global WP_Query in the render function. |
|
| 115 | + $query_args['post__in'] = $paid_courses_not_taken; |
|
| 116 | + $query_args['posts_per_page'] = $this->number; |
|
| 117 | + $this->query = new WP_Query( $query_args ); |
|
| 118 | + |
|
| 119 | + }// end setup _course_query |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Rendering the shortcode this class is responsible for. |
|
| 123 | - * |
|
| 124 | - * @return string $content |
|
| 125 | - */ |
|
| 126 | - public function render(){ |
|
| 121 | + /** |
|
| 122 | + * Rendering the shortcode this class is responsible for. |
|
| 123 | + * |
|
| 124 | + * @return string $content |
|
| 125 | + */ |
|
| 126 | + public function render(){ |
|
| 127 | 127 | |
| 128 | - global $wp_query; |
|
| 128 | + global $wp_query; |
|
| 129 | 129 | |
| 130 | - if( ! is_user_logged_in() ) { |
|
| 131 | - return ''; |
|
| 132 | - } |
|
| 130 | + if( ! is_user_logged_in() ) { |
|
| 131 | + return ''; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - // keep a reference to old query |
|
| 135 | - $current_global_query = $wp_query; |
|
| 134 | + // keep a reference to old query |
|
| 135 | + $current_global_query = $wp_query; |
|
| 136 | 136 | |
| 137 | - // assign the query setup in $this-> setup_course_query |
|
| 138 | - $wp_query = $this->query; |
|
| 137 | + // assign the query setup in $this-> setup_course_query |
|
| 138 | + $wp_query = $this->query; |
|
| 139 | 139 | |
| 140 | - ob_start(); |
|
| 141 | - Sensei_Templates::get_template('loop-course.php'); |
|
| 142 | - $shortcode_output = ob_get_clean(); |
|
| 140 | + ob_start(); |
|
| 141 | + Sensei_Templates::get_template('loop-course.php'); |
|
| 142 | + $shortcode_output = ob_get_clean(); |
|
| 143 | 143 | |
| 144 | - //restore old query |
|
| 145 | - $wp_query = $current_global_query; |
|
| 144 | + //restore old query |
|
| 145 | + $wp_query = $current_global_query; |
|
| 146 | 146 | |
| 147 | - return $shortcode_output; |
|
| 147 | + return $shortcode_output; |
|
| 148 | 148 | |
| 149 | - }// end render |
|
| 149 | + }// end render |
|
| 150 | 150 | |
| 151 | 151 | } |
| 152 | 152 | \ 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_unpurchased_courses] shortcode when a user is logged in. If the user is not logged in |
@@ -45,25 +45,25 @@ discard block |
||
| 45 | 45 | * @param string $content |
| 46 | 46 | * @param string $shortcode the shortcode that was called for this instance |
| 47 | 47 | */ |
| 48 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 48 | + public function __construct($attributes, $content, $shortcode) { |
|
| 49 | 49 | |
| 50 | - if( !is_user_logged_in() ) { |
|
| 50 | + if ( ! is_user_logged_in()) { |
|
| 51 | 51 | return; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | // set up all argument need for constructing the course query |
| 55 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 56 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 55 | + $this->number = isset($attributes['number']) ? $attributes['number'] : '10'; |
|
| 56 | + $this->orderby = isset($attributes['orderby']) ? $attributes['orderby'] : 'title'; |
|
| 57 | 57 | |
| 58 | 58 | // set the default for menu_order to be ASC |
| 59 | - if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 59 | + if ('menu_order' == $this->orderby && ! isset($attributes['order'])) { |
|
| 60 | 60 | |
| 61 | - $this->order = 'ASC'; |
|
| 61 | + $this->order = 'ASC'; |
|
| 62 | 62 | |
| 63 | - }else{ |
|
| 63 | + } else { |
|
| 64 | 64 | |
| 65 | 65 | // for everything else use the value passed or the default DESC |
| 66 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
|
| 66 | + $this->order = isset($attributes['order']) ? $attributes['order'] : 'DESC'; |
|
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @since 1.9.0 |
| 79 | 79 | */ |
| 80 | - protected function setup_course_query(){ |
|
| 80 | + protected function setup_course_query() { |
|
| 81 | 81 | |
| 82 | 82 | // course query parameters to be used for all courses |
| 83 | 83 | $query_args = array( |
@@ -90,18 +90,18 @@ discard block |
||
| 90 | 90 | ); |
| 91 | 91 | |
| 92 | 92 | // get all the courses that has a product attached |
| 93 | - $all_courses_query = new WP_Query( $query_args ); |
|
| 93 | + $all_courses_query = new WP_Query($query_args); |
|
| 94 | 94 | |
| 95 | 95 | $paid_courses_not_taken = array(); |
| 96 | 96 | // look through all course and find the purchasable ones that user has not purchased |
| 97 | - foreach( $all_courses_query->posts as $course ){ |
|
| 97 | + foreach ($all_courses_query->posts as $course) { |
|
| 98 | 98 | |
| 99 | 99 | // only keep the courses with a product including only courses that the user not taking |
| 100 | - $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true ); |
|
| 101 | - if( is_numeric( $course_product_id ) |
|
| 100 | + $course_product_id = get_post_meta($course->ID, '_course_woocommerce_product', true); |
|
| 101 | + if (is_numeric($course_product_id) |
|
| 102 | 102 | && |
| 103 | - ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id() ) |
|
| 104 | - ){ |
|
| 103 | + ! Sensei_Utils::user_started_course($course->ID, get_current_user_id()) |
|
| 104 | + ) { |
|
| 105 | 105 | |
| 106 | 106 | $paid_courses_not_taken[] = $course->ID; |
| 107 | 107 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | // this query will be loaded into the global WP_Query in the render function. |
| 115 | 115 | $query_args['post__in'] = $paid_courses_not_taken; |
| 116 | 116 | $query_args['posts_per_page'] = $this->number; |
| 117 | - $this->query = new WP_Query( $query_args ); |
|
| 117 | + $this->query = new WP_Query($query_args); |
|
| 118 | 118 | |
| 119 | 119 | }// end setup _course_query |
| 120 | 120 | |
@@ -123,11 +123,11 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @return string $content |
| 125 | 125 | */ |
| 126 | - public function render(){ |
|
| 126 | + public function render() { |
|
| 127 | 127 | |
| 128 | 128 | global $wp_query; |
| 129 | 129 | |
| 130 | - if( ! is_user_logged_in() ) { |
|
| 130 | + if ( ! is_user_logged_in()) { |
|
| 131 | 131 | return ''; |
| 132 | 132 | } |
| 133 | 133 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | |
| 140 | 140 | ob_start(); |
| 141 | 141 | Sensei_Templates::get_template('loop-course.php'); |
| 142 | - $shortcode_output = ob_get_clean(); |
|
| 142 | + $shortcode_output = ob_get_clean(); |
|
| 143 | 143 | |
| 144 | 144 | //restore old query |
| 145 | 145 | $wp_query = $current_global_query; |
@@ -12,735 +12,735 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | Class Sensei_WC{ |
| 15 | - /** |
|
| 16 | - * Load the files needed for the woocommerce integration. |
|
| 17 | - * |
|
| 18 | - * @since 1.9.0 |
|
| 19 | - */ |
|
| 20 | - public static function load_woocommerce_integration_hooks(){ |
|
| 15 | + /** |
|
| 16 | + * Load the files needed for the woocommerce integration. |
|
| 17 | + * |
|
| 18 | + * @since 1.9.0 |
|
| 19 | + */ |
|
| 20 | + public static function load_woocommerce_integration_hooks(){ |
|
| 21 | 21 | |
| 22 | - require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
| 22 | + require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
| 23 | 23 | |
| 24 | - } |
|
| 25 | - /** |
|
| 26 | - * check if WooCommerce plugin is loaded and allowed by Sensei |
|
| 27 | - * |
|
| 28 | - * @since 1.9.0 |
|
| 29 | - * @return bool |
|
| 30 | - */ |
|
| 31 | - public static function is_woocommerce_active(){ |
|
| 24 | + } |
|
| 25 | + /** |
|
| 26 | + * check if WooCommerce plugin is loaded and allowed by Sensei |
|
| 27 | + * |
|
| 28 | + * @since 1.9.0 |
|
| 29 | + * @return bool |
|
| 30 | + */ |
|
| 31 | + public static function is_woocommerce_active(){ |
|
| 32 | 32 | |
| 33 | - $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 34 | - return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
| 33 | + $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 34 | + return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
| 35 | 35 | |
| 36 | - } // end is_woocommerce_active |
|
| 36 | + } // end is_woocommerce_active |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Checks if the WooCommerce plugin is installed and activation. |
|
| 40 | - * |
|
| 41 | - * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
| 42 | - * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
| 43 | - * |
|
| 44 | - * @since 1.9.0 |
|
| 45 | - * |
|
| 46 | - * @return bool |
|
| 47 | - */ |
|
| 48 | - public static function is_woocommerce_present(){ |
|
| 38 | + /** |
|
| 39 | + * Checks if the WooCommerce plugin is installed and activation. |
|
| 40 | + * |
|
| 41 | + * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
| 42 | + * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
| 43 | + * |
|
| 44 | + * @since 1.9.0 |
|
| 45 | + * |
|
| 46 | + * @return bool |
|
| 47 | + */ |
|
| 48 | + public static function is_woocommerce_present(){ |
|
| 49 | 49 | |
| 50 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 50 | + $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 51 | 51 | |
| 52 | - if ( is_multisite() ){ |
|
| 52 | + if ( is_multisite() ){ |
|
| 53 | 53 | |
| 54 | - $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 54 | + $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 55 | 55 | |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 58 | + $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 59 | 59 | |
| 60 | - return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
| 60 | + return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
| 61 | 61 | |
| 62 | - }// end is_woocommerce_present |
|
| 62 | + }// end is_woocommerce_present |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
| 66 | - * |
|
| 67 | - * If multiple exist we will return the latest order. |
|
| 68 | - * |
|
| 69 | - * @param $user_id |
|
| 70 | - * @param $course_id |
|
| 71 | - * @return array $user_course_orders |
|
| 72 | - */ |
|
| 73 | - public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 64 | + /** |
|
| 65 | + * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
| 66 | + * |
|
| 67 | + * If multiple exist we will return the latest order. |
|
| 68 | + * |
|
| 69 | + * @param $user_id |
|
| 70 | + * @param $course_id |
|
| 71 | + * @return array $user_course_orders |
|
| 72 | + */ |
|
| 73 | + public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 74 | 74 | |
| 75 | - $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 75 | + $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 76 | 76 | |
| 77 | - $orders_query = new WP_Query( array( |
|
| 78 | - 'post_type' => 'shop_order', |
|
| 79 | - 'posts_per_page' => -1, |
|
| 80 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 81 | - 'meta_key'=> '_customer_user', |
|
| 82 | - 'meta_value'=> $user_id, |
|
| 83 | - ) ); |
|
| 77 | + $orders_query = new WP_Query( array( |
|
| 78 | + 'post_type' => 'shop_order', |
|
| 79 | + 'posts_per_page' => -1, |
|
| 80 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 81 | + 'meta_key'=> '_customer_user', |
|
| 82 | + 'meta_value'=> $user_id, |
|
| 83 | + ) ); |
|
| 84 | 84 | |
| 85 | - if( $orders_query->post_count == 0 ){ |
|
| 85 | + if( $orders_query->post_count == 0 ){ |
|
| 86 | 86 | |
| 87 | - return false; |
|
| 87 | + return false; |
|
| 88 | 88 | |
| 89 | - } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - foreach( $orders_query->get_posts() as $order ){ |
|
| 91 | + foreach( $orders_query->get_posts() as $order ){ |
|
| 92 | 92 | |
| 93 | - $order = new WC_Order( $order->ID ); |
|
| 94 | - $items = $order->get_items(); |
|
| 93 | + $order = new WC_Order( $order->ID ); |
|
| 94 | + $items = $order->get_items(); |
|
| 95 | 95 | |
| 96 | - $user_orders = array(); |
|
| 96 | + $user_orders = array(); |
|
| 97 | 97 | |
| 98 | - foreach( $items as $item ){ |
|
| 98 | + foreach( $items as $item ){ |
|
| 99 | 99 | |
| 100 | - // if the product id on the order and the one given to this function |
|
| 101 | - // this order has been placed by the given user on the given course. |
|
| 102 | - $product = wc_get_product( $item['product_id'] ); |
|
| 100 | + // if the product id on the order and the one given to this function |
|
| 101 | + // this order has been placed by the given user on the given course. |
|
| 102 | + $product = wc_get_product( $item['product_id'] ); |
|
| 103 | 103 | |
| 104 | - if ( $product->is_type( 'variable' )) { |
|
| 104 | + if ( $product->is_type( 'variable' )) { |
|
| 105 | 105 | |
| 106 | - $item_product_id = $item['variation_id']; |
|
| 106 | + $item_product_id = $item['variation_id']; |
|
| 107 | 107 | |
| 108 | - } else { |
|
| 108 | + } else { |
|
| 109 | 109 | |
| 110 | - $item_product_id = $item['product_id']; |
|
| 110 | + $item_product_id = $item['product_id']; |
|
| 111 | 111 | |
| 112 | - } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - if( $course_product_id == $item_product_id ){ |
|
| 114 | + if( $course_product_id == $item_product_id ){ |
|
| 115 | 115 | |
| 116 | - return $order->id; |
|
| 116 | + return $order->id; |
|
| 117 | 117 | |
| 118 | - } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | |
| 121 | - }//end for each order item |
|
| 121 | + }//end for each order item |
|
| 122 | 122 | |
| 123 | - } // end for each order |
|
| 123 | + } // end for each order |
|
| 124 | 124 | |
| 125 | - // if we reach this place we found no order |
|
| 126 | - return false; |
|
| 125 | + // if we reach this place we found no order |
|
| 126 | + return false; |
|
| 127 | 127 | |
| 128 | - } // end get_learner_course_active_order_ids |
|
| 128 | + } // end get_learner_course_active_order_ids |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Output WooCommerce specific course filters |
|
| 132 | - * Removing the paged argument |
|
| 133 | - * |
|
| 134 | - * @since 1.9.0 |
|
| 135 | - * @param $filter_links |
|
| 136 | - * @return mixed |
|
| 137 | - */ |
|
| 138 | - public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 130 | + /** |
|
| 131 | + * Output WooCommerce specific course filters |
|
| 132 | + * Removing the paged argument |
|
| 133 | + * |
|
| 134 | + * @since 1.9.0 |
|
| 135 | + * @param $filter_links |
|
| 136 | + * @return mixed |
|
| 137 | + */ |
|
| 138 | + public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 139 | 139 | |
| 140 | - $course_url = remove_query_arg('paged', Sensei_Utils::get_current_url() ); |
|
| 140 | + $course_url = remove_query_arg('paged', Sensei_Utils::get_current_url() ); |
|
| 141 | 141 | |
| 142 | - $free_courses = self::get_free_courses(); |
|
| 143 | - $paid_courses = self::get_paid_courses(); |
|
| 142 | + $free_courses = self::get_free_courses(); |
|
| 143 | + $paid_courses = self::get_paid_courses(); |
|
| 144 | 144 | |
| 145 | - if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 146 | - // do not show any WooCommerce filters if all courses are |
|
| 147 | - // free or if all courses are paid |
|
| 148 | - return $filter_links; |
|
| 145 | + if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 146 | + // do not show any WooCommerce filters if all courses are |
|
| 147 | + // free or if all courses are paid |
|
| 148 | + return $filter_links; |
|
| 149 | 149 | |
| 150 | - } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - $filter_links[] = array( 'id'=>'paid' , |
|
| 153 | - 'url'=> add_query_arg('course_filter', 'paid', $course_url), |
|
| 154 | - 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 155 | - ); |
|
| 152 | + $filter_links[] = array( 'id'=>'paid' , |
|
| 153 | + 'url'=> add_query_arg('course_filter', 'paid', $course_url), |
|
| 154 | + 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 155 | + ); |
|
| 156 | 156 | |
| 157 | - $filter_links[] = array( 'id'=>'free', |
|
| 158 | - 'url'=>add_query_arg('course_filter', 'free', $course_url), |
|
| 159 | - 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 160 | - ); |
|
| 157 | + $filter_links[] = array( 'id'=>'free', |
|
| 158 | + 'url'=>add_query_arg('course_filter', 'free', $course_url), |
|
| 159 | + 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 160 | + ); |
|
| 161 | 161 | |
| 162 | - return $filter_links; |
|
| 162 | + return $filter_links; |
|
| 163 | 163 | |
| 164 | - }// end add_course_archive_wc_filter_links |
|
| 164 | + }// end add_course_archive_wc_filter_links |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Apply the free filter the the course query |
|
| 168 | - * getting all course with no products or products with zero price |
|
| 169 | - * |
|
| 170 | - * hooked into pre_get_posts |
|
| 171 | - * |
|
| 172 | - * @since 1.9.0 |
|
| 173 | - * @param WP_Query $query |
|
| 174 | - * @return WP_Query $query |
|
| 175 | - */ |
|
| 176 | - public static function course_archive_wc_filter_free( $query ){ |
|
| 166 | + /** |
|
| 167 | + * Apply the free filter the the course query |
|
| 168 | + * getting all course with no products or products with zero price |
|
| 169 | + * |
|
| 170 | + * hooked into pre_get_posts |
|
| 171 | + * |
|
| 172 | + * @since 1.9.0 |
|
| 173 | + * @param WP_Query $query |
|
| 174 | + * @return WP_Query $query |
|
| 175 | + */ |
|
| 176 | + public static function course_archive_wc_filter_free( $query ){ |
|
| 177 | 177 | |
| 178 | - if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 179 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 178 | + if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 179 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 180 | 180 | |
| 181 | - // setup the course meta query |
|
| 182 | - $meta_query = self::get_free_courses_meta_query_args(); |
|
| 181 | + // setup the course meta query |
|
| 182 | + $meta_query = self::get_free_courses_meta_query_args(); |
|
| 183 | 183 | |
| 184 | - // manipulate the query to return free courses |
|
| 185 | - $query->set('meta_query', $meta_query ); |
|
| 184 | + // manipulate the query to return free courses |
|
| 185 | + $query->set('meta_query', $meta_query ); |
|
| 186 | 186 | |
| 187 | - // don't show any paid courses |
|
| 188 | - $courses = self::get_paid_courses(); |
|
| 189 | - $ids = array(); |
|
| 190 | - foreach( $courses as $course ){ |
|
| 191 | - $ids[] = $course->ID; |
|
| 192 | - } |
|
| 193 | - $query->set( 'post__not_in', $ids ); |
|
| 187 | + // don't show any paid courses |
|
| 188 | + $courses = self::get_paid_courses(); |
|
| 189 | + $ids = array(); |
|
| 190 | + foreach( $courses as $course ){ |
|
| 191 | + $ids[] = $course->ID; |
|
| 192 | + } |
|
| 193 | + $query->set( 'post__not_in', $ids ); |
|
| 194 | 194 | |
| 195 | - }// end if course_filter |
|
| 195 | + }// end if course_filter |
|
| 196 | 196 | |
| 197 | - return $query; |
|
| 197 | + return $query; |
|
| 198 | 198 | |
| 199 | - }// course_archive_wc_filter_free |
|
| 199 | + }// course_archive_wc_filter_free |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Apply the paid filter to the course query on the courses page |
|
| 203 | - * will include all course with a product attached with a price |
|
| 204 | - * more than 0 |
|
| 205 | - * |
|
| 206 | - * hooked into pre_get_posts |
|
| 207 | - * |
|
| 208 | - * @since 1.9.0 |
|
| 209 | - * @param WP_Query $query |
|
| 210 | - * @return WP_Query $query |
|
| 211 | - */ |
|
| 212 | - public static function course_archive_wc_filter_paid( $query ){ |
|
| 201 | + /** |
|
| 202 | + * Apply the paid filter to the course query on the courses page |
|
| 203 | + * will include all course with a product attached with a price |
|
| 204 | + * more than 0 |
|
| 205 | + * |
|
| 206 | + * hooked into pre_get_posts |
|
| 207 | + * |
|
| 208 | + * @since 1.9.0 |
|
| 209 | + * @param WP_Query $query |
|
| 210 | + * @return WP_Query $query |
|
| 211 | + */ |
|
| 212 | + public static function course_archive_wc_filter_paid( $query ){ |
|
| 213 | 213 | |
| 214 | - if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 215 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 214 | + if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 215 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 216 | 216 | |
| 217 | - // setup the course meta query |
|
| 218 | - $meta_query = self::get_paid_courses_meta_query_args(); |
|
| 217 | + // setup the course meta query |
|
| 218 | + $meta_query = self::get_paid_courses_meta_query_args(); |
|
| 219 | 219 | |
| 220 | - // manipulate the query to return free courses |
|
| 221 | - $query->set('meta_query', $meta_query ); |
|
| 222 | - |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - return $query; |
|
| 226 | - |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Load the WooCommerce single product actions above |
|
| 231 | - * single courses if woocommerce is active allowing purchase |
|
| 232 | - * information and actions to be hooked from WooCommerce. |
|
| 233 | - */ |
|
| 234 | - public static function do_single_course_wc_single_product_action(){ |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * this hooks is documented within the WooCommerce plugin. |
|
| 238 | - */ |
|
| 239 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 240 | - |
|
| 241 | - do_action( 'woocommerce_before_single_product' ); |
|
| 242 | - |
|
| 243 | - } // End If Statement |
|
| 244 | - |
|
| 245 | - }// end do_single_course_wc_single_product_action |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Hooking into the single lesson page to alter the |
|
| 249 | - * user access permissions based on if they have purchased the |
|
| 250 | - * course the lesson belongs to. |
|
| 251 | - * |
|
| 252 | - * This function will only return false or the passed in user_access value. |
|
| 253 | - * It doesn't return true in order to avoid altering other options. |
|
| 254 | - * |
|
| 255 | - * @since 1.9.0 |
|
| 256 | - * |
|
| 257 | - * @param $can_user_view_lesson |
|
| 258 | - * @param $lesson_id |
|
| 259 | - * @param $user_id |
|
| 260 | - * @return bool |
|
| 261 | - */ |
|
| 262 | - public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 263 | - |
|
| 264 | - // check if the course has a valid product attached to it |
|
| 265 | - // which the user should have purchased if they want to access |
|
| 266 | - // the current lesson |
|
| 267 | - $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 268 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 269 | - $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 270 | - if( isset ($product) && is_object($product) ){ |
|
| 271 | - |
|
| 272 | - // valid product found |
|
| 273 | - $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 274 | - |
|
| 275 | - // product has a successful order so this user may access the content |
|
| 276 | - // this function may only return false or the default |
|
| 277 | - // returning true may override other negatives which we don't want |
|
| 278 | - if( ! $order_id ){ |
|
| 279 | - |
|
| 280 | - return false; |
|
| 281 | - |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - // return the passed in value |
|
| 287 | - return $can_user_view_lesson; |
|
| 288 | - |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Add course link to order thank you and details pages. |
|
| 293 | - * |
|
| 294 | - * @since 1.4.5 |
|
| 295 | - * @access public |
|
| 296 | - * |
|
| 297 | - * @return void |
|
| 298 | - */ |
|
| 299 | - public static function course_link_from_order( ) { |
|
| 300 | - |
|
| 301 | - if( ! is_order_received_page() ){ |
|
| 302 | - return; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - $order_id = get_query_var( 'order-received' ); |
|
| 220 | + // manipulate the query to return free courses |
|
| 221 | + $query->set('meta_query', $meta_query ); |
|
| 222 | + |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + return $query; |
|
| 226 | + |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Load the WooCommerce single product actions above |
|
| 231 | + * single courses if woocommerce is active allowing purchase |
|
| 232 | + * information and actions to be hooked from WooCommerce. |
|
| 233 | + */ |
|
| 234 | + public static function do_single_course_wc_single_product_action(){ |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * this hooks is documented within the WooCommerce plugin. |
|
| 238 | + */ |
|
| 239 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 240 | + |
|
| 241 | + do_action( 'woocommerce_before_single_product' ); |
|
| 242 | + |
|
| 243 | + } // End If Statement |
|
| 244 | + |
|
| 245 | + }// end do_single_course_wc_single_product_action |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Hooking into the single lesson page to alter the |
|
| 249 | + * user access permissions based on if they have purchased the |
|
| 250 | + * course the lesson belongs to. |
|
| 251 | + * |
|
| 252 | + * This function will only return false or the passed in user_access value. |
|
| 253 | + * It doesn't return true in order to avoid altering other options. |
|
| 254 | + * |
|
| 255 | + * @since 1.9.0 |
|
| 256 | + * |
|
| 257 | + * @param $can_user_view_lesson |
|
| 258 | + * @param $lesson_id |
|
| 259 | + * @param $user_id |
|
| 260 | + * @return bool |
|
| 261 | + */ |
|
| 262 | + public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 263 | + |
|
| 264 | + // check if the course has a valid product attached to it |
|
| 265 | + // which the user should have purchased if they want to access |
|
| 266 | + // the current lesson |
|
| 267 | + $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 268 | + $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 269 | + $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 270 | + if( isset ($product) && is_object($product) ){ |
|
| 271 | + |
|
| 272 | + // valid product found |
|
| 273 | + $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 274 | + |
|
| 275 | + // product has a successful order so this user may access the content |
|
| 276 | + // this function may only return false or the default |
|
| 277 | + // returning true may override other negatives which we don't want |
|
| 278 | + if( ! $order_id ){ |
|
| 279 | + |
|
| 280 | + return false; |
|
| 281 | + |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + // return the passed in value |
|
| 287 | + return $can_user_view_lesson; |
|
| 288 | + |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Add course link to order thank you and details pages. |
|
| 293 | + * |
|
| 294 | + * @since 1.4.5 |
|
| 295 | + * @access public |
|
| 296 | + * |
|
| 297 | + * @return void |
|
| 298 | + */ |
|
| 299 | + public static function course_link_from_order( ) { |
|
| 300 | + |
|
| 301 | + if( ! is_order_received_page() ){ |
|
| 302 | + return; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + $order_id = get_query_var( 'order-received' ); |
|
| 306 | 306 | $order = new WC_Order( $order_id ); |
| 307 | 307 | |
| 308 | 308 | // exit early if not wc-completed or wc-processing |
| 309 | 309 | if( 'wc-completed' != $order->post_status |
| 310 | - && 'wc-processing' != $order->post_status ) { |
|
| 311 | - return; |
|
| 312 | - } |
|
| 310 | + && 'wc-processing' != $order->post_status ) { |
|
| 311 | + return; |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - $course_links = array(); // store the for links for courses purchased |
|
| 314 | + $course_links = array(); // store the for links for courses purchased |
|
| 315 | 315 | foreach ( $order->get_items() as $item ) { |
| 316 | 316 | |
| 317 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 317 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 318 | 318 | |
| 319 | - // If item has variation_id then its a variation of the product |
|
| 320 | - $item_id = $item['variation_id']; |
|
| 319 | + // If item has variation_id then its a variation of the product |
|
| 320 | + $item_id = $item['variation_id']; |
|
| 321 | 321 | |
| 322 | - } else { |
|
| 322 | + } else { |
|
| 323 | 323 | |
| 324 | - //If not its real product set its id to item_id |
|
| 325 | - $item_id = $item['product_id']; |
|
| 324 | + //If not its real product set its id to item_id |
|
| 325 | + $item_id = $item['product_id']; |
|
| 326 | 326 | |
| 327 | - } // End If Statement |
|
| 327 | + } // End If Statement |
|
| 328 | 328 | |
| 329 | - $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 329 | + $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 330 | 330 | |
| 331 | - if( $user_id ) { |
|
| 331 | + if( $user_id ) { |
|
| 332 | 332 | |
| 333 | - // Get all courses for product |
|
| 334 | - $args = Sensei_Course::get_default_query_args(); |
|
| 335 | - $args['meta_query'] = array( array( |
|
| 336 | - 'key' => '_course_woocommerce_product', |
|
| 337 | - 'value' => $item_id |
|
| 338 | - ) ); |
|
| 339 | - $args['orderby'] = 'menu_order date'; |
|
| 340 | - $args['order'] = 'ASC'; |
|
| 333 | + // Get all courses for product |
|
| 334 | + $args = Sensei_Course::get_default_query_args(); |
|
| 335 | + $args['meta_query'] = array( array( |
|
| 336 | + 'key' => '_course_woocommerce_product', |
|
| 337 | + 'value' => $item_id |
|
| 338 | + ) ); |
|
| 339 | + $args['orderby'] = 'menu_order date'; |
|
| 340 | + $args['order'] = 'ASC'; |
|
| 341 | 341 | |
| 342 | - // loop through courses |
|
| 343 | - $courses = get_posts( $args ); |
|
| 344 | - if( $courses && count( $courses ) > 0 ) { |
|
| 342 | + // loop through courses |
|
| 343 | + $courses = get_posts( $args ); |
|
| 344 | + if( $courses && count( $courses ) > 0 ) { |
|
| 345 | 345 | |
| 346 | - foreach( $courses as $course ) { |
|
| 346 | + foreach( $courses as $course ) { |
|
| 347 | 347 | |
| 348 | - $title = $course->post_title; |
|
| 349 | - $permalink = get_permalink( $course->ID ); |
|
| 350 | - $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 348 | + $title = $course->post_title; |
|
| 349 | + $permalink = get_permalink( $course->ID ); |
|
| 350 | + $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 351 | 351 | |
| 352 | - } // end for each |
|
| 352 | + } // end for each |
|
| 353 | 353 | |
| 354 | - // close the message div |
|
| 354 | + // close the message div |
|
| 355 | 355 | |
| 356 | - }// end if $courses check |
|
| 357 | - } |
|
| 358 | - }// end loop through orders |
|
| 356 | + }// end if $courses check |
|
| 357 | + } |
|
| 358 | + }// end loop through orders |
|
| 359 | 359 | |
| 360 | - // add the courses to the WooCommerce notice |
|
| 361 | - if( ! empty( $course_links) ){ |
|
| 360 | + // add the courses to the WooCommerce notice |
|
| 361 | + if( ! empty( $course_links) ){ |
|
| 362 | 362 | |
| 363 | - $courses_html = _nx( |
|
| 364 | - 'You have purchased the following course:', |
|
| 365 | - 'You have purchased the following courses:', |
|
| 366 | - count( $course_links ), |
|
| 367 | - 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
| 368 | - ); |
|
| 363 | + $courses_html = _nx( |
|
| 364 | + 'You have purchased the following course:', |
|
| 365 | + 'You have purchased the following courses:', |
|
| 366 | + count( $course_links ), |
|
| 367 | + 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
| 368 | + ); |
|
| 369 | 369 | |
| 370 | - foreach( $course_links as $link ){ |
|
| 370 | + foreach( $course_links as $link ){ |
|
| 371 | 371 | |
| 372 | - $courses_html .= '<li>' . $link . '</li>'; |
|
| 372 | + $courses_html .= '<li>' . $link . '</li>'; |
|
| 373 | 373 | |
| 374 | - } |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - $courses_html .= ' </ul>'; |
|
| 376 | + $courses_html .= ' </ul>'; |
|
| 377 | 377 | |
| 378 | - wc_add_notice( $courses_html, 'success' ); |
|
| 379 | - } |
|
| 378 | + wc_add_notice( $courses_html, 'success' ); |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | 381 | } // end course_link_order_form |
| 382 | 382 | |
| 383 | - /** |
|
| 384 | - * Show the message that a user should complete |
|
| 385 | - * their purchase if the course is in the cart |
|
| 386 | - * |
|
| 387 | - * This should be used within the course loop or single course page |
|
| 388 | - * |
|
| 389 | - * @since 1.9.0 |
|
| 390 | - */ |
|
| 391 | - public static function course_in_cart_message(){ |
|
| 383 | + /** |
|
| 384 | + * Show the message that a user should complete |
|
| 385 | + * their purchase if the course is in the cart |
|
| 386 | + * |
|
| 387 | + * This should be used within the course loop or single course page |
|
| 388 | + * |
|
| 389 | + * @since 1.9.0 |
|
| 390 | + */ |
|
| 391 | + public static function course_in_cart_message(){ |
|
| 392 | 392 | |
| 393 | - global $post; |
|
| 393 | + global $post; |
|
| 394 | 394 | |
| 395 | - if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 395 | + if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 396 | 396 | |
| 397 | 397 | <div class="sensei-message info">' |
| 398 | 398 | <?php |
| 399 | 399 | |
| 400 | - $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 401 | - . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 402 | - . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 400 | + $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 401 | + . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 402 | + . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 403 | 403 | |
| 404 | - sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 404 | + sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 405 | 405 | |
| 406 | - ?> |
|
| 406 | + ?> |
|
| 407 | 407 | </div> |
| 408 | 408 | <?php } |
| 409 | 409 | |
| 410 | - } // End sensei_woocommerce_in_cart_message() |
|
| 410 | + } // End sensei_woocommerce_in_cart_message() |
|
| 411 | 411 | |
| 412 | - /** |
|
| 413 | - * Checks the cart to see if a course is in the cart. |
|
| 414 | - * |
|
| 415 | - * @param $course_id |
|
| 416 | - * @return bool |
|
| 417 | - */ |
|
| 418 | - public static function is_course_in_cart( $course_id ){ |
|
| 419 | - |
|
| 420 | - $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 421 | - $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 422 | - |
|
| 423 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 424 | - |
|
| 425 | - if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 426 | - |
|
| 427 | - return true; |
|
| 428 | - |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - return false; |
|
| 434 | - |
|
| 435 | - }// is_course_in_cart |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Check the cart to see if the product is in the cart |
|
| 439 | - * |
|
| 440 | - * @param $product_id |
|
| 441 | - * @return bool |
|
| 442 | - */ |
|
| 443 | - public static function is_product_in_cart( $product_id ){ |
|
| 444 | - |
|
| 445 | - if ( 0 < $product_id ) { |
|
| 446 | - |
|
| 447 | - $product = wc_get_product( $product_id ); |
|
| 448 | - |
|
| 449 | - $parent_id = ''; |
|
| 450 | - if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 451 | - $wc_product_id = $product->parent->id; |
|
| 452 | - } |
|
| 453 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 454 | - |
|
| 455 | - $cart_product = $values['data']; |
|
| 456 | - if( $product_id == $cart_product->id ) { |
|
| 457 | - |
|
| 458 | - return true; |
|
| 459 | - |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - } |
|
| 463 | - } // End If Statement |
|
| 464 | - |
|
| 465 | - return false; |
|
| 466 | - |
|
| 467 | - } // end is_product_in_car |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Get all free WooCommerce products |
|
| 471 | - * |
|
| 472 | - * @since 1.9.0 |
|
| 473 | - * |
|
| 474 | - * @return array $free_products{ |
|
| 475 | - * @type int $wp_post_id |
|
| 476 | - * } |
|
| 477 | - */ |
|
| 478 | - public static function get_free_product_ids(){ |
|
| 479 | - |
|
| 480 | - return get_posts( array( |
|
| 481 | - 'post_type' => 'product', |
|
| 482 | - 'posts_per_page' => '1000', |
|
| 483 | - 'fields' => 'ids', |
|
| 484 | - 'meta_query'=> array( |
|
| 485 | - 'relation' => 'OR', |
|
| 486 | - array( |
|
| 487 | - 'key'=> '_regular_price', |
|
| 488 | - 'value' => 0, |
|
| 489 | - ), |
|
| 490 | - array( |
|
| 491 | - 'key'=> '_sale_price', |
|
| 492 | - 'value' => 0, |
|
| 493 | - ), |
|
| 494 | - ), |
|
| 495 | - )); |
|
| 496 | - |
|
| 497 | - }// end get free product query |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * The metat query for courses that are free |
|
| 501 | - * |
|
| 502 | - * @since 1.9.0 |
|
| 503 | - * @return array $wp_meta_query_param |
|
| 504 | - */ |
|
| 505 | - public static function get_free_courses_meta_query_args(){ |
|
| 506 | - |
|
| 507 | - return array( |
|
| 508 | - 'relation' => 'OR', |
|
| 509 | - array( |
|
| 510 | - 'key' => '_course_woocommerce_product', |
|
| 511 | - 'value' => '-', |
|
| 512 | - 'compare' => '=', |
|
| 513 | - ), |
|
| 514 | - array( |
|
| 515 | - 'key' => '_course_woocommerce_product', |
|
| 516 | - 'value' => self::get_free_product_ids(), |
|
| 517 | - 'compare' => 'IN', |
|
| 518 | - ), |
|
| 519 | - ); |
|
| 520 | - |
|
| 521 | - }// get_free_courses_meta_query |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * The metat query for courses that are free |
|
| 525 | - * |
|
| 526 | - * @since 1.9.0 |
|
| 527 | - * @return array $wp_query_meta_query_args_param |
|
| 528 | - */ |
|
| 529 | - public static function get_paid_courses_meta_query_args(){ |
|
| 530 | - |
|
| 531 | - $paid_product_ids = self::get_paid_product_ids(); |
|
| 532 | - |
|
| 533 | - return array( |
|
| 534 | - array( |
|
| 535 | - 'key' => '_course_woocommerce_product', |
|
| 536 | - // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
| 537 | - // query |
|
| 538 | - 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 539 | - 'compare' => 'IN', |
|
| 540 | - ), |
|
| 541 | - ); |
|
| 542 | - |
|
| 543 | - }// get_free_courses_meta_query |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * The WordPress Query args |
|
| 547 | - * for paid products on sale |
|
| 548 | - * |
|
| 549 | - * @since 1.9.0 |
|
| 550 | - * @return array $product_query_args |
|
| 551 | - */ |
|
| 552 | - public static function get_paid_products_on_sale_query_args(){ |
|
| 553 | - |
|
| 554 | - $args = array( |
|
| 555 | - 'post_type' => 'product', |
|
| 556 | - 'posts_per_page' => 1000, |
|
| 557 | - 'orderby' => 'date', |
|
| 558 | - 'order' => 'DESC', |
|
| 559 | - 'suppress_filters' => 0 |
|
| 560 | - ); |
|
| 561 | - |
|
| 562 | - $args[ 'fields' ] = 'ids'; |
|
| 563 | - |
|
| 564 | - $args[ 'meta_query' ] = array( |
|
| 565 | - 'relation' => 'AND', |
|
| 566 | - array( |
|
| 567 | - 'key'=> '_regular_price', |
|
| 568 | - 'compare' => '>', |
|
| 569 | - 'value' => 0, |
|
| 570 | - ), |
|
| 571 | - array( |
|
| 572 | - 'key'=> '_sale_price', |
|
| 573 | - 'compare' => '>', |
|
| 574 | - 'value' => 0, |
|
| 575 | - ), |
|
| 576 | - ); |
|
| 577 | - |
|
| 578 | - return $args; |
|
| 579 | - |
|
| 580 | - } // get_paid_products_on_sale_query_args |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Return the WordPress query args for |
|
| 585 | - * products not on sale but that is not a free |
|
| 586 | - * |
|
| 587 | - * @since 1.9.0 |
|
| 588 | - * |
|
| 589 | - * @return array |
|
| 590 | - */ |
|
| 591 | - public static function get_paid_products_not_on_sale_query_args(){ |
|
| 592 | - |
|
| 593 | - $args = array( |
|
| 594 | - 'post_type' => 'product', |
|
| 595 | - 'posts_per_page' => 1000, |
|
| 596 | - 'orderby' => 'date', |
|
| 597 | - 'order' => 'DESC', |
|
| 598 | - 'suppress_filters' => 0 |
|
| 599 | - ); |
|
| 600 | - |
|
| 601 | - $args[ 'fields' ] = 'ids'; |
|
| 602 | - $args[ 'meta_query' ] = array( |
|
| 603 | - 'relation' => 'AND', |
|
| 604 | - array( |
|
| 605 | - 'key'=> '_regular_price', |
|
| 606 | - 'compare' => '>', |
|
| 607 | - 'value' => 0, |
|
| 608 | - ), |
|
| 609 | - array( |
|
| 610 | - 'key'=> '_sale_price', |
|
| 611 | - 'compare' => '=', |
|
| 612 | - 'value' => '', |
|
| 613 | - ), |
|
| 614 | - ); |
|
| 615 | - |
|
| 616 | - return $args; |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - } // get_paid_courses_meta_query |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Get all WooCommerce non-free product id's |
|
| 623 | - * |
|
| 624 | - * @since 1.9.0 |
|
| 625 | - * |
|
| 626 | - * @return array $woocommerce_paid_product_ids |
|
| 627 | - */ |
|
| 628 | - public static function get_paid_product_ids(){ |
|
| 629 | - |
|
| 630 | - // get all the paid WooCommerce products that has regular |
|
| 631 | - // and sale price greater than 0 |
|
| 632 | - // will be used later to check for course with the id as meta |
|
| 633 | - $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 634 | - |
|
| 635 | - // get all the paid WooCommerce products that has regular price |
|
| 636 | - // greater than 0 without a sale price |
|
| 637 | - // will be used later to check for course with the id as meta |
|
| 638 | - $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 639 | - |
|
| 640 | - // combine products ID's with regular and sale price grater than zero and those without |
|
| 641 | - // sale but regular price greater than zero |
|
| 642 | - $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 643 | - |
|
| 644 | - // if |
|
| 645 | - if( empty($woocommerce_paid_product_ids) ){ |
|
| 646 | - return array( ); |
|
| 647 | - } |
|
| 648 | - return $woocommerce_paid_product_ids; |
|
| 649 | - |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * Get all free courses. |
|
| 654 | - * |
|
| 655 | - * This course that have a WC product attached |
|
| 656 | - * that has a price or sale price of zero and |
|
| 657 | - * other courses with no WooCommerce products |
|
| 658 | - * attached. |
|
| 659 | - * |
|
| 660 | - * @since 1.9.0 |
|
| 661 | - * |
|
| 662 | - * @return array |
|
| 663 | - */ |
|
| 664 | - public static function get_free_courses(){ |
|
| 665 | - |
|
| 666 | - $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 667 | - $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 668 | - |
|
| 669 | - // don't show any paid courses |
|
| 670 | - $courses = self::get_paid_courses(); |
|
| 671 | - $ids = array(); |
|
| 672 | - foreach( $courses as $course ){ |
|
| 673 | - $ids[] = $course->ID; |
|
| 674 | - } |
|
| 675 | - $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 676 | - |
|
| 677 | - return get_posts( $free_course_query_args ); |
|
| 678 | - |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * Return all products that are not free |
|
| 683 | - * |
|
| 684 | - * @since 1.9.0 |
|
| 685 | - * @return array |
|
| 686 | - */ |
|
| 687 | - public static function get_paid_courses(){ |
|
| 688 | - |
|
| 689 | - $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 690 | - |
|
| 691 | - $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 692 | - |
|
| 693 | - return get_posts( $paid_course_query_args ); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Show the WooCommerce add to cart button for the current course |
|
| 698 | - * |
|
| 699 | - * The function will only show the button if |
|
| 700 | - * 1- the user can buy the course |
|
| 701 | - * 2- if they have completed their pre-requisite |
|
| 702 | - * 3- if the course has a valid product attached |
|
| 703 | - * |
|
| 704 | - * @since 1.9.0 |
|
| 705 | - * @param int $course_id |
|
| 706 | - * @return string $html markup for the button or nothing if user not allowed to buy |
|
| 707 | - */ |
|
| 708 | - public static function the_add_to_cart_button_html( $course_id ){ |
|
| 709 | - |
|
| 710 | - if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
| 711 | - return ''; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 715 | - |
|
| 716 | - // Check if customer purchased the product |
|
| 717 | - if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 718 | - || empty( $wc_post_id ) ) { |
|
| 719 | - |
|
| 720 | - return ''; |
|
| 721 | - |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - // based on simple.php in WC templates/single-product/add-to-cart/ |
|
| 725 | - // Get the product |
|
| 726 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 727 | - |
|
| 728 | - // do not show the button for invalid products, non purchasable products, out |
|
| 729 | - // of stock product or if course is already in cart |
|
| 730 | - if ( ! isset ( $product ) |
|
| 731 | - || ! is_object( $product ) |
|
| 732 | - || ! $product->is_purchasable() |
|
| 733 | - || ! $product->is_in_stock() |
|
| 734 | - || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 735 | - |
|
| 736 | - return ''; |
|
| 737 | - |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - // |
|
| 741 | - // button output: |
|
| 742 | - // |
|
| 743 | - ?> |
|
| 412 | + /** |
|
| 413 | + * Checks the cart to see if a course is in the cart. |
|
| 414 | + * |
|
| 415 | + * @param $course_id |
|
| 416 | + * @return bool |
|
| 417 | + */ |
|
| 418 | + public static function is_course_in_cart( $course_id ){ |
|
| 419 | + |
|
| 420 | + $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 421 | + $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 422 | + |
|
| 423 | + if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 424 | + |
|
| 425 | + if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 426 | + |
|
| 427 | + return true; |
|
| 428 | + |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + return false; |
|
| 434 | + |
|
| 435 | + }// is_course_in_cart |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Check the cart to see if the product is in the cart |
|
| 439 | + * |
|
| 440 | + * @param $product_id |
|
| 441 | + * @return bool |
|
| 442 | + */ |
|
| 443 | + public static function is_product_in_cart( $product_id ){ |
|
| 444 | + |
|
| 445 | + if ( 0 < $product_id ) { |
|
| 446 | + |
|
| 447 | + $product = wc_get_product( $product_id ); |
|
| 448 | + |
|
| 449 | + $parent_id = ''; |
|
| 450 | + if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 451 | + $wc_product_id = $product->parent->id; |
|
| 452 | + } |
|
| 453 | + foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 454 | + |
|
| 455 | + $cart_product = $values['data']; |
|
| 456 | + if( $product_id == $cart_product->id ) { |
|
| 457 | + |
|
| 458 | + return true; |
|
| 459 | + |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + } |
|
| 463 | + } // End If Statement |
|
| 464 | + |
|
| 465 | + return false; |
|
| 466 | + |
|
| 467 | + } // end is_product_in_car |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Get all free WooCommerce products |
|
| 471 | + * |
|
| 472 | + * @since 1.9.0 |
|
| 473 | + * |
|
| 474 | + * @return array $free_products{ |
|
| 475 | + * @type int $wp_post_id |
|
| 476 | + * } |
|
| 477 | + */ |
|
| 478 | + public static function get_free_product_ids(){ |
|
| 479 | + |
|
| 480 | + return get_posts( array( |
|
| 481 | + 'post_type' => 'product', |
|
| 482 | + 'posts_per_page' => '1000', |
|
| 483 | + 'fields' => 'ids', |
|
| 484 | + 'meta_query'=> array( |
|
| 485 | + 'relation' => 'OR', |
|
| 486 | + array( |
|
| 487 | + 'key'=> '_regular_price', |
|
| 488 | + 'value' => 0, |
|
| 489 | + ), |
|
| 490 | + array( |
|
| 491 | + 'key'=> '_sale_price', |
|
| 492 | + 'value' => 0, |
|
| 493 | + ), |
|
| 494 | + ), |
|
| 495 | + )); |
|
| 496 | + |
|
| 497 | + }// end get free product query |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * The metat query for courses that are free |
|
| 501 | + * |
|
| 502 | + * @since 1.9.0 |
|
| 503 | + * @return array $wp_meta_query_param |
|
| 504 | + */ |
|
| 505 | + public static function get_free_courses_meta_query_args(){ |
|
| 506 | + |
|
| 507 | + return array( |
|
| 508 | + 'relation' => 'OR', |
|
| 509 | + array( |
|
| 510 | + 'key' => '_course_woocommerce_product', |
|
| 511 | + 'value' => '-', |
|
| 512 | + 'compare' => '=', |
|
| 513 | + ), |
|
| 514 | + array( |
|
| 515 | + 'key' => '_course_woocommerce_product', |
|
| 516 | + 'value' => self::get_free_product_ids(), |
|
| 517 | + 'compare' => 'IN', |
|
| 518 | + ), |
|
| 519 | + ); |
|
| 520 | + |
|
| 521 | + }// get_free_courses_meta_query |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * The metat query for courses that are free |
|
| 525 | + * |
|
| 526 | + * @since 1.9.0 |
|
| 527 | + * @return array $wp_query_meta_query_args_param |
|
| 528 | + */ |
|
| 529 | + public static function get_paid_courses_meta_query_args(){ |
|
| 530 | + |
|
| 531 | + $paid_product_ids = self::get_paid_product_ids(); |
|
| 532 | + |
|
| 533 | + return array( |
|
| 534 | + array( |
|
| 535 | + 'key' => '_course_woocommerce_product', |
|
| 536 | + // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
| 537 | + // query |
|
| 538 | + 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 539 | + 'compare' => 'IN', |
|
| 540 | + ), |
|
| 541 | + ); |
|
| 542 | + |
|
| 543 | + }// get_free_courses_meta_query |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * The WordPress Query args |
|
| 547 | + * for paid products on sale |
|
| 548 | + * |
|
| 549 | + * @since 1.9.0 |
|
| 550 | + * @return array $product_query_args |
|
| 551 | + */ |
|
| 552 | + public static function get_paid_products_on_sale_query_args(){ |
|
| 553 | + |
|
| 554 | + $args = array( |
|
| 555 | + 'post_type' => 'product', |
|
| 556 | + 'posts_per_page' => 1000, |
|
| 557 | + 'orderby' => 'date', |
|
| 558 | + 'order' => 'DESC', |
|
| 559 | + 'suppress_filters' => 0 |
|
| 560 | + ); |
|
| 561 | + |
|
| 562 | + $args[ 'fields' ] = 'ids'; |
|
| 563 | + |
|
| 564 | + $args[ 'meta_query' ] = array( |
|
| 565 | + 'relation' => 'AND', |
|
| 566 | + array( |
|
| 567 | + 'key'=> '_regular_price', |
|
| 568 | + 'compare' => '>', |
|
| 569 | + 'value' => 0, |
|
| 570 | + ), |
|
| 571 | + array( |
|
| 572 | + 'key'=> '_sale_price', |
|
| 573 | + 'compare' => '>', |
|
| 574 | + 'value' => 0, |
|
| 575 | + ), |
|
| 576 | + ); |
|
| 577 | + |
|
| 578 | + return $args; |
|
| 579 | + |
|
| 580 | + } // get_paid_products_on_sale_query_args |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Return the WordPress query args for |
|
| 585 | + * products not on sale but that is not a free |
|
| 586 | + * |
|
| 587 | + * @since 1.9.0 |
|
| 588 | + * |
|
| 589 | + * @return array |
|
| 590 | + */ |
|
| 591 | + public static function get_paid_products_not_on_sale_query_args(){ |
|
| 592 | + |
|
| 593 | + $args = array( |
|
| 594 | + 'post_type' => 'product', |
|
| 595 | + 'posts_per_page' => 1000, |
|
| 596 | + 'orderby' => 'date', |
|
| 597 | + 'order' => 'DESC', |
|
| 598 | + 'suppress_filters' => 0 |
|
| 599 | + ); |
|
| 600 | + |
|
| 601 | + $args[ 'fields' ] = 'ids'; |
|
| 602 | + $args[ 'meta_query' ] = array( |
|
| 603 | + 'relation' => 'AND', |
|
| 604 | + array( |
|
| 605 | + 'key'=> '_regular_price', |
|
| 606 | + 'compare' => '>', |
|
| 607 | + 'value' => 0, |
|
| 608 | + ), |
|
| 609 | + array( |
|
| 610 | + 'key'=> '_sale_price', |
|
| 611 | + 'compare' => '=', |
|
| 612 | + 'value' => '', |
|
| 613 | + ), |
|
| 614 | + ); |
|
| 615 | + |
|
| 616 | + return $args; |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + } // get_paid_courses_meta_query |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * Get all WooCommerce non-free product id's |
|
| 623 | + * |
|
| 624 | + * @since 1.9.0 |
|
| 625 | + * |
|
| 626 | + * @return array $woocommerce_paid_product_ids |
|
| 627 | + */ |
|
| 628 | + public static function get_paid_product_ids(){ |
|
| 629 | + |
|
| 630 | + // get all the paid WooCommerce products that has regular |
|
| 631 | + // and sale price greater than 0 |
|
| 632 | + // will be used later to check for course with the id as meta |
|
| 633 | + $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 634 | + |
|
| 635 | + // get all the paid WooCommerce products that has regular price |
|
| 636 | + // greater than 0 without a sale price |
|
| 637 | + // will be used later to check for course with the id as meta |
|
| 638 | + $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 639 | + |
|
| 640 | + // combine products ID's with regular and sale price grater than zero and those without |
|
| 641 | + // sale but regular price greater than zero |
|
| 642 | + $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 643 | + |
|
| 644 | + // if |
|
| 645 | + if( empty($woocommerce_paid_product_ids) ){ |
|
| 646 | + return array( ); |
|
| 647 | + } |
|
| 648 | + return $woocommerce_paid_product_ids; |
|
| 649 | + |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * Get all free courses. |
|
| 654 | + * |
|
| 655 | + * This course that have a WC product attached |
|
| 656 | + * that has a price or sale price of zero and |
|
| 657 | + * other courses with no WooCommerce products |
|
| 658 | + * attached. |
|
| 659 | + * |
|
| 660 | + * @since 1.9.0 |
|
| 661 | + * |
|
| 662 | + * @return array |
|
| 663 | + */ |
|
| 664 | + public static function get_free_courses(){ |
|
| 665 | + |
|
| 666 | + $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 667 | + $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 668 | + |
|
| 669 | + // don't show any paid courses |
|
| 670 | + $courses = self::get_paid_courses(); |
|
| 671 | + $ids = array(); |
|
| 672 | + foreach( $courses as $course ){ |
|
| 673 | + $ids[] = $course->ID; |
|
| 674 | + } |
|
| 675 | + $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 676 | + |
|
| 677 | + return get_posts( $free_course_query_args ); |
|
| 678 | + |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * Return all products that are not free |
|
| 683 | + * |
|
| 684 | + * @since 1.9.0 |
|
| 685 | + * @return array |
|
| 686 | + */ |
|
| 687 | + public static function get_paid_courses(){ |
|
| 688 | + |
|
| 689 | + $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 690 | + |
|
| 691 | + $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 692 | + |
|
| 693 | + return get_posts( $paid_course_query_args ); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Show the WooCommerce add to cart button for the current course |
|
| 698 | + * |
|
| 699 | + * The function will only show the button if |
|
| 700 | + * 1- the user can buy the course |
|
| 701 | + * 2- if they have completed their pre-requisite |
|
| 702 | + * 3- if the course has a valid product attached |
|
| 703 | + * |
|
| 704 | + * @since 1.9.0 |
|
| 705 | + * @param int $course_id |
|
| 706 | + * @return string $html markup for the button or nothing if user not allowed to buy |
|
| 707 | + */ |
|
| 708 | + public static function the_add_to_cart_button_html( $course_id ){ |
|
| 709 | + |
|
| 710 | + if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
| 711 | + return ''; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 715 | + |
|
| 716 | + // Check if customer purchased the product |
|
| 717 | + if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 718 | + || empty( $wc_post_id ) ) { |
|
| 719 | + |
|
| 720 | + return ''; |
|
| 721 | + |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + // based on simple.php in WC templates/single-product/add-to-cart/ |
|
| 725 | + // Get the product |
|
| 726 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 727 | + |
|
| 728 | + // do not show the button for invalid products, non purchasable products, out |
|
| 729 | + // of stock product or if course is already in cart |
|
| 730 | + if ( ! isset ( $product ) |
|
| 731 | + || ! is_object( $product ) |
|
| 732 | + || ! $product->is_purchasable() |
|
| 733 | + || ! $product->is_in_stock() |
|
| 734 | + || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 735 | + |
|
| 736 | + return ''; |
|
| 737 | + |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + // |
|
| 741 | + // button output: |
|
| 742 | + // |
|
| 743 | + ?> |
|
| 744 | 744 | |
| 745 | 745 | <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" |
| 746 | 746 | class="cart" |
@@ -773,54 +773,54 @@ discard block |
||
| 773 | 773 | </form> |
| 774 | 774 | |
| 775 | 775 | <?php |
| 776 | - } // end the_add_to_cart_button_html |
|
| 776 | + } // end the_add_to_cart_button_html |
|
| 777 | 777 | |
| 778 | - /** |
|
| 779 | - * Alter the no permissions message on the single course page |
|
| 780 | - * Changes the message to a WooCommerce specific message. |
|
| 781 | - * |
|
| 782 | - * @since 1.9.0 |
|
| 783 | - * |
|
| 784 | - * @param $message |
|
| 785 | - * @param $post_id |
|
| 786 | - * |
|
| 787 | - * @return string $message |
|
| 788 | - */ |
|
| 789 | - public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 778 | + /** |
|
| 779 | + * Alter the no permissions message on the single course page |
|
| 780 | + * Changes the message to a WooCommerce specific message. |
|
| 781 | + * |
|
| 782 | + * @since 1.9.0 |
|
| 783 | + * |
|
| 784 | + * @param $message |
|
| 785 | + * @param $post_id |
|
| 786 | + * |
|
| 787 | + * @return string $message |
|
| 788 | + */ |
|
| 789 | + public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 790 | 790 | |
| 791 | - if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 792 | - return $message; |
|
| 793 | - } |
|
| 791 | + if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 792 | + return $message; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - $product_id = self::get_course_product_id( $post_id ); |
|
| 795 | + $product_id = self::get_course_product_id( $post_id ); |
|
| 796 | 796 | |
| 797 | - if( ! $product_id |
|
| 798 | - || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 797 | + if( ! $product_id |
|
| 798 | + || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 799 | 799 | |
| 800 | - return $message; |
|
| 800 | + return $message; |
|
| 801 | 801 | |
| 802 | - } |
|
| 802 | + } |
|
| 803 | 803 | |
| 804 | - ob_start(); |
|
| 805 | - self::the_course_no_permissions_message( $post_id ); |
|
| 806 | - $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
| 804 | + ob_start(); |
|
| 805 | + self::the_course_no_permissions_message( $post_id ); |
|
| 806 | + $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
| 807 | 807 | |
| 808 | - return $woocommerce_course_no_permissions_message ; |
|
| 808 | + return $woocommerce_course_no_permissions_message ; |
|
| 809 | 809 | |
| 810 | - } |
|
| 811 | - /** |
|
| 812 | - * Show the no permissions message when a user is logged in |
|
| 813 | - * and have not yet purchased the current course |
|
| 814 | - * |
|
| 815 | - * @since 1.9.0 |
|
| 816 | - */ |
|
| 817 | - public static function the_course_no_permissions_message( $course_id ){ |
|
| 810 | + } |
|
| 811 | + /** |
|
| 812 | + * Show the no permissions message when a user is logged in |
|
| 813 | + * and have not yet purchased the current course |
|
| 814 | + * |
|
| 815 | + * @since 1.9.0 |
|
| 816 | + */ |
|
| 817 | + public static function the_course_no_permissions_message( $course_id ){ |
|
| 818 | 818 | |
| 819 | - // login link |
|
| 820 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 821 | - $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 819 | + // login link |
|
| 820 | + $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 821 | + $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 822 | 822 | |
| 823 | - ?> |
|
| 823 | + ?> |
|
| 824 | 824 | |
| 825 | 825 | <span class="add-to-cart-login"> |
| 826 | 826 | <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?> |
@@ -828,110 +828,110 @@ discard block |
||
| 828 | 828 | |
| 829 | 829 | <?php } |
| 830 | 830 | |
| 831 | - /** |
|
| 832 | - * Checks if a user has bought a product item. |
|
| 833 | - * |
|
| 834 | - * @since 1.9.0 |
|
| 835 | - * |
|
| 836 | - * @param int $user_id |
|
| 837 | - * @param int $product_id |
|
| 838 | - * |
|
| 839 | - * @return bool |
|
| 840 | - */ |
|
| 841 | - public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 831 | + /** |
|
| 832 | + * Checks if a user has bought a product item. |
|
| 833 | + * |
|
| 834 | + * @since 1.9.0 |
|
| 835 | + * |
|
| 836 | + * @param int $user_id |
|
| 837 | + * @param int $product_id |
|
| 838 | + * |
|
| 839 | + * @return bool |
|
| 840 | + */ |
|
| 841 | + public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 842 | 842 | |
| 843 | - $orders = get_posts( array( |
|
| 844 | - 'posts_per_page' => -1, |
|
| 845 | - 'meta_key' => '_customer_user', |
|
| 846 | - 'meta_value' => intval( $user_id ), |
|
| 847 | - 'post_type' => 'shop_order', |
|
| 848 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 849 | - ) ); |
|
| 843 | + $orders = get_posts( array( |
|
| 844 | + 'posts_per_page' => -1, |
|
| 845 | + 'meta_key' => '_customer_user', |
|
| 846 | + 'meta_value' => intval( $user_id ), |
|
| 847 | + 'post_type' => 'shop_order', |
|
| 848 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 849 | + ) ); |
|
| 850 | 850 | |
| 851 | - foreach ( $orders as $order_id ) { |
|
| 851 | + foreach ( $orders as $order_id ) { |
|
| 852 | 852 | |
| 853 | - $order = new WC_Order( $order_id->ID ); |
|
| 853 | + $order = new WC_Order( $order_id->ID ); |
|
| 854 | 854 | |
| 855 | - if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
| 855 | + if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
| 856 | 856 | |
| 857 | - continue; |
|
| 858 | - } |
|
| 857 | + continue; |
|
| 858 | + } |
|
| 859 | 859 | |
| 860 | - if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
| 860 | + if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
| 861 | 861 | |
| 862 | - continue; |
|
| 862 | + continue; |
|
| 863 | 863 | |
| 864 | - } |
|
| 864 | + } |
|
| 865 | 865 | |
| 866 | - foreach( $order->get_items() as $item ) { |
|
| 866 | + foreach( $order->get_items() as $item ) { |
|
| 867 | 867 | |
| 868 | - // Check if user has bought product |
|
| 869 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 868 | + // Check if user has bought product |
|
| 869 | + if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 870 | 870 | |
| 871 | - // Check if user has an active subscription for product |
|
| 872 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 873 | - $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
| 874 | - if( $sub_key ) { |
|
| 875 | - $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
| 876 | - if( $sub && isset( $sub['status'] ) ) { |
|
| 877 | - if( 'active' == $sub['status'] ) { |
|
| 878 | - return true; |
|
| 879 | - } else { |
|
| 880 | - return false; |
|
| 881 | - } |
|
| 882 | - } |
|
| 883 | - } |
|
| 884 | - } |
|
| 871 | + // Check if user has an active subscription for product |
|
| 872 | + if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 873 | + $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
| 874 | + if( $sub_key ) { |
|
| 875 | + $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
| 876 | + if( $sub && isset( $sub['status'] ) ) { |
|
| 877 | + if( 'active' == $sub['status'] ) { |
|
| 878 | + return true; |
|
| 879 | + } else { |
|
| 880 | + return false; |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | + } |
|
| 884 | + } |
|
| 885 | 885 | |
| 886 | - // Customer has bought product |
|
| 887 | - return true; |
|
| 888 | - } // End If Statement |
|
| 886 | + // Customer has bought product |
|
| 887 | + return true; |
|
| 888 | + } // End If Statement |
|
| 889 | 889 | |
| 890 | - } // End For each item |
|
| 890 | + } // End For each item |
|
| 891 | 891 | |
| 892 | - } // End For each order |
|
| 892 | + } // End For each order |
|
| 893 | 893 | |
| 894 | - } // end has customer bought product |
|
| 894 | + } // end has customer bought product |
|
| 895 | 895 | |
| 896 | - /** |
|
| 897 | - * Return the product id for the given course |
|
| 898 | - * |
|
| 899 | - * @since 1.9.0 |
|
| 900 | - * |
|
| 901 | - * @param int $course_id |
|
| 902 | - * |
|
| 903 | - * @return string $woocommerce_product_id or false if none exist |
|
| 904 | - * |
|
| 905 | - */ |
|
| 906 | - public static function get_course_product_id( $course_id ){ |
|
| 896 | + /** |
|
| 897 | + * Return the product id for the given course |
|
| 898 | + * |
|
| 899 | + * @since 1.9.0 |
|
| 900 | + * |
|
| 901 | + * @param int $course_id |
|
| 902 | + * |
|
| 903 | + * @return string $woocommerce_product_id or false if none exist |
|
| 904 | + * |
|
| 905 | + */ |
|
| 906 | + public static function get_course_product_id( $course_id ){ |
|
| 907 | 907 | |
| 908 | - $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 908 | + $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 909 | 909 | |
| 910 | - if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 911 | - return false; |
|
| 912 | - } |
|
| 910 | + if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 911 | + return false; |
|
| 912 | + } |
|
| 913 | 913 | |
| 914 | - return $product_id; |
|
| 914 | + return $product_id; |
|
| 915 | 915 | |
| 916 | - } |
|
| 916 | + } |
|
| 917 | 917 | |
| 918 | - /** |
|
| 919 | - * Alter the body classes adding WooCommerce to the body |
|
| 920 | - * |
|
| 921 | - * @param array $classes |
|
| 922 | - * @return array |
|
| 923 | - */ |
|
| 924 | - public static function add_woocommerce_body_class( $classes ){ |
|
| 918 | + /** |
|
| 919 | + * Alter the body classes adding WooCommerce to the body |
|
| 920 | + * |
|
| 921 | + * @param array $classes |
|
| 922 | + * @return array |
|
| 923 | + */ |
|
| 924 | + public static function add_woocommerce_body_class( $classes ){ |
|
| 925 | 925 | |
| 926 | - if( ! in_array( 'woocommerce', $classes ) ){ |
|
| 926 | + if( ! in_array( 'woocommerce', $classes ) ){ |
|
| 927 | 927 | |
| 928 | - $classes[] ='woocommerce'; |
|
| 928 | + $classes[] ='woocommerce'; |
|
| 929 | 929 | |
| 930 | - } |
|
| 930 | + } |
|
| 931 | 931 | |
| 932 | 932 | |
| 933 | - return $classes; |
|
| 933 | + return $classes; |
|
| 934 | 934 | |
| 935 | - } |
|
| 935 | + } |
|
| 936 | 936 | |
| 937 | 937 | }// end Sensei_WC |
@@ -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 | /** |
| 5 | 5 | * Sensei WooCommerce class |
@@ -11,15 +11,15 @@ discard block |
||
| 11 | 11 | * @since 1.9.0 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -Class Sensei_WC{ |
|
| 14 | +Class Sensei_WC { |
|
| 15 | 15 | /** |
| 16 | 16 | * Load the files needed for the woocommerce integration. |
| 17 | 17 | * |
| 18 | 18 | * @since 1.9.0 |
| 19 | 19 | */ |
| 20 | - public static function load_woocommerce_integration_hooks(){ |
|
| 20 | + public static function load_woocommerce_integration_hooks() { |
|
| 21 | 21 | |
| 22 | - require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
| 22 | + require_once(__DIR__.'/hooks/woocommerce.php'); |
|
| 23 | 23 | |
| 24 | 24 | } |
| 25 | 25 | /** |
@@ -28,9 +28,9 @@ discard block |
||
| 28 | 28 | * @since 1.9.0 |
| 29 | 29 | * @return bool |
| 30 | 30 | */ |
| 31 | - public static function is_woocommerce_active(){ |
|
| 31 | + public static function is_woocommerce_active() { |
|
| 32 | 32 | |
| 33 | - $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 33 | + $is_woocommerce_enabled_in_settings = isset(Sensei()->settings->settings['woocommerce_enabled']) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 34 | 34 | return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
| 35 | 35 | |
| 36 | 36 | } // end is_woocommerce_active |
@@ -45,19 +45,19 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return bool |
| 47 | 47 | */ |
| 48 | - public static function is_woocommerce_present(){ |
|
| 48 | + public static function is_woocommerce_present() { |
|
| 49 | 49 | |
| 50 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 50 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
| 51 | 51 | |
| 52 | - if ( is_multisite() ){ |
|
| 52 | + if (is_multisite()) { |
|
| 53 | 53 | |
| 54 | - $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 54 | + $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array())); |
|
| 55 | 55 | |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 58 | + $is_woocommerce_plugin_present_and_activated = in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins); |
|
| 59 | 59 | |
| 60 | - return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
| 60 | + return class_exists('Woocommerce') || $is_woocommerce_plugin_present_and_activated; |
|
| 61 | 61 | |
| 62 | 62 | }// end is_woocommerce_present |
| 63 | 63 | |
@@ -70,48 +70,48 @@ discard block |
||
| 70 | 70 | * @param $course_id |
| 71 | 71 | * @return array $user_course_orders |
| 72 | 72 | */ |
| 73 | - public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 73 | + public static function get_learner_course_active_order_id($user_id, $course_id) { |
|
| 74 | 74 | |
| 75 | - $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 75 | + $course_product_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
| 76 | 76 | |
| 77 | - $orders_query = new WP_Query( array( |
|
| 77 | + $orders_query = new WP_Query(array( |
|
| 78 | 78 | 'post_type' => 'shop_order', |
| 79 | 79 | 'posts_per_page' => -1, |
| 80 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 80 | + 'post_status' => array('wc-processing', 'wc-completed'), |
|
| 81 | 81 | 'meta_key'=> '_customer_user', |
| 82 | 82 | 'meta_value'=> $user_id, |
| 83 | - ) ); |
|
| 83 | + )); |
|
| 84 | 84 | |
| 85 | - if( $orders_query->post_count == 0 ){ |
|
| 85 | + if ($orders_query->post_count == 0) { |
|
| 86 | 86 | |
| 87 | 87 | return false; |
| 88 | 88 | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - foreach( $orders_query->get_posts() as $order ){ |
|
| 91 | + foreach ($orders_query->get_posts() as $order) { |
|
| 92 | 92 | |
| 93 | - $order = new WC_Order( $order->ID ); |
|
| 93 | + $order = new WC_Order($order->ID); |
|
| 94 | 94 | $items = $order->get_items(); |
| 95 | 95 | |
| 96 | - $user_orders = array(); |
|
| 96 | + $user_orders = array(); |
|
| 97 | 97 | |
| 98 | - foreach( $items as $item ){ |
|
| 98 | + foreach ($items as $item) { |
|
| 99 | 99 | |
| 100 | 100 | // if the product id on the order and the one given to this function |
| 101 | 101 | // this order has been placed by the given user on the given course. |
| 102 | - $product = wc_get_product( $item['product_id'] ); |
|
| 102 | + $product = wc_get_product($item['product_id']); |
|
| 103 | 103 | |
| 104 | - if ( $product->is_type( 'variable' )) { |
|
| 104 | + if ($product->is_type('variable')) { |
|
| 105 | 105 | |
| 106 | 106 | $item_product_id = $item['variation_id']; |
| 107 | 107 | |
| 108 | 108 | } else { |
| 109 | 109 | |
| 110 | - $item_product_id = $item['product_id']; |
|
| 110 | + $item_product_id = $item['product_id']; |
|
| 111 | 111 | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if( $course_product_id == $item_product_id ){ |
|
| 114 | + if ($course_product_id == $item_product_id) { |
|
| 115 | 115 | |
| 116 | 116 | return $order->id; |
| 117 | 117 | |
@@ -135,28 +135,28 @@ discard block |
||
| 135 | 135 | * @param $filter_links |
| 136 | 136 | * @return mixed |
| 137 | 137 | */ |
| 138 | - public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 138 | + public static function add_course_archive_wc_filter_links($filter_links) { |
|
| 139 | 139 | |
| 140 | - $course_url = remove_query_arg('paged', Sensei_Utils::get_current_url() ); |
|
| 140 | + $course_url = remove_query_arg('paged', Sensei_Utils::get_current_url()); |
|
| 141 | 141 | |
| 142 | 142 | $free_courses = self::get_free_courses(); |
| 143 | 143 | $paid_courses = self::get_paid_courses(); |
| 144 | 144 | |
| 145 | - if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 145 | + if (empty($free_courses) || empty($paid_courses)) { |
|
| 146 | 146 | // do not show any WooCommerce filters if all courses are |
| 147 | 147 | // free or if all courses are paid |
| 148 | 148 | return $filter_links; |
| 149 | 149 | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - $filter_links[] = array( 'id'=>'paid' , |
|
| 152 | + $filter_links[] = array('id'=>'paid', |
|
| 153 | 153 | 'url'=> add_query_arg('course_filter', 'paid', $course_url), |
| 154 | - 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 154 | + 'title'=>__('Paid', 'woothemes-sensei') |
|
| 155 | 155 | ); |
| 156 | 156 | |
| 157 | - $filter_links[] = array( 'id'=>'free', |
|
| 157 | + $filter_links[] = array('id'=>'free', |
|
| 158 | 158 | 'url'=>add_query_arg('course_filter', 'free', $course_url), |
| 159 | - 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 159 | + 'title'=>__('Free', 'woothemes-sensei') |
|
| 160 | 160 | ); |
| 161 | 161 | |
| 162 | 162 | return $filter_links; |
@@ -173,24 +173,24 @@ discard block |
||
| 173 | 173 | * @param WP_Query $query |
| 174 | 174 | * @return WP_Query $query |
| 175 | 175 | */ |
| 176 | - public static function course_archive_wc_filter_free( $query ){ |
|
| 176 | + public static function course_archive_wc_filter_free($query) { |
|
| 177 | 177 | |
| 178 | - if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 179 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 178 | + if (isset($_GET['course_filter']) && 'free' == $_GET['course_filter'] |
|
| 179 | + && 'course' == $query->get('post_type') && $query->is_main_query()) { |
|
| 180 | 180 | |
| 181 | 181 | // setup the course meta query |
| 182 | 182 | $meta_query = self::get_free_courses_meta_query_args(); |
| 183 | 183 | |
| 184 | 184 | // manipulate the query to return free courses |
| 185 | - $query->set('meta_query', $meta_query ); |
|
| 185 | + $query->set('meta_query', $meta_query); |
|
| 186 | 186 | |
| 187 | 187 | // don't show any paid courses |
| 188 | 188 | $courses = self::get_paid_courses(); |
| 189 | 189 | $ids = array(); |
| 190 | - foreach( $courses as $course ){ |
|
| 190 | + foreach ($courses as $course) { |
|
| 191 | 191 | $ids[] = $course->ID; |
| 192 | 192 | } |
| 193 | - $query->set( 'post__not_in', $ids ); |
|
| 193 | + $query->set('post__not_in', $ids); |
|
| 194 | 194 | |
| 195 | 195 | }// end if course_filter |
| 196 | 196 | |
@@ -209,16 +209,16 @@ discard block |
||
| 209 | 209 | * @param WP_Query $query |
| 210 | 210 | * @return WP_Query $query |
| 211 | 211 | */ |
| 212 | - public static function course_archive_wc_filter_paid( $query ){ |
|
| 212 | + public static function course_archive_wc_filter_paid($query) { |
|
| 213 | 213 | |
| 214 | - if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 215 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 214 | + if (isset($_GET['course_filter']) && 'paid' == $_GET['course_filter'] |
|
| 215 | + && 'course' == $query->get('post_type') && $query->is_main_query()) { |
|
| 216 | 216 | |
| 217 | 217 | // setup the course meta query |
| 218 | 218 | $meta_query = self::get_paid_courses_meta_query_args(); |
| 219 | 219 | |
| 220 | 220 | // manipulate the query to return free courses |
| 221 | - $query->set('meta_query', $meta_query ); |
|
| 221 | + $query->set('meta_query', $meta_query); |
|
| 222 | 222 | |
| 223 | 223 | } |
| 224 | 224 | |
@@ -231,14 +231,14 @@ discard block |
||
| 231 | 231 | * single courses if woocommerce is active allowing purchase |
| 232 | 232 | * information and actions to be hooked from WooCommerce. |
| 233 | 233 | */ |
| 234 | - public static function do_single_course_wc_single_product_action(){ |
|
| 234 | + public static function do_single_course_wc_single_product_action() { |
|
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | 237 | * this hooks is documented within the WooCommerce plugin. |
| 238 | 238 | */ |
| 239 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 239 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 240 | 240 | |
| 241 | - do_action( 'woocommerce_before_single_product' ); |
|
| 241 | + do_action('woocommerce_before_single_product'); |
|
| 242 | 242 | |
| 243 | 243 | } // End If Statement |
| 244 | 244 | |
@@ -259,23 +259,23 @@ discard block |
||
| 259 | 259 | * @param $user_id |
| 260 | 260 | * @return bool |
| 261 | 261 | */ |
| 262 | - public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 262 | + public static function alter_can_user_view_lesson($can_user_view_lesson, $lesson_id, $user_id) { |
|
| 263 | 263 | |
| 264 | 264 | // check if the course has a valid product attached to it |
| 265 | 265 | // which the user should have purchased if they want to access |
| 266 | 266 | // the current lesson |
| 267 | - $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 268 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 267 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 268 | + $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
| 269 | 269 | $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
| 270 | - if( isset ($product) && is_object($product) ){ |
|
| 270 | + if (isset ($product) && is_object($product)) { |
|
| 271 | 271 | |
| 272 | 272 | // valid product found |
| 273 | - $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 273 | + $order_id = self::get_learner_course_active_order_id($user_id, $course_id); |
|
| 274 | 274 | |
| 275 | 275 | // product has a successful order so this user may access the content |
| 276 | 276 | // this function may only return false or the default |
| 277 | 277 | // returning true may override other negatives which we don't want |
| 278 | - if( ! $order_id ){ |
|
| 278 | + if ( ! $order_id) { |
|
| 279 | 279 | |
| 280 | 280 | return false; |
| 281 | 281 | |
@@ -298,23 +298,23 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | public static function course_link_from_order( ) { |
| 300 | 300 | |
| 301 | - if( ! is_order_received_page() ){ |
|
| 301 | + if ( ! is_order_received_page()) { |
|
| 302 | 302 | return; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - $order_id = get_query_var( 'order-received' ); |
|
| 306 | - $order = new WC_Order( $order_id ); |
|
| 305 | + $order_id = get_query_var('order-received'); |
|
| 306 | + $order = new WC_Order($order_id); |
|
| 307 | 307 | |
| 308 | 308 | // exit early if not wc-completed or wc-processing |
| 309 | - if( 'wc-completed' != $order->post_status |
|
| 310 | - && 'wc-processing' != $order->post_status ) { |
|
| 309 | + if ('wc-completed' != $order->post_status |
|
| 310 | + && 'wc-processing' != $order->post_status) { |
|
| 311 | 311 | return; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | $course_links = array(); // store the for links for courses purchased |
| 315 | - foreach ( $order->get_items() as $item ) { |
|
| 315 | + foreach ($order->get_items() as $item) { |
|
| 316 | 316 | |
| 317 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 317 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 318 | 318 | |
| 319 | 319 | // If item has variation_id then its a variation of the product |
| 320 | 320 | $item_id = $item['variation_id']; |
@@ -326,28 +326,28 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | } // End If Statement |
| 328 | 328 | |
| 329 | - $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 329 | + $user_id = get_post_meta($order->id, '_customer_user', true); |
|
| 330 | 330 | |
| 331 | - if( $user_id ) { |
|
| 331 | + if ($user_id) { |
|
| 332 | 332 | |
| 333 | 333 | // Get all courses for product |
| 334 | 334 | $args = Sensei_Course::get_default_query_args(); |
| 335 | - $args['meta_query'] = array( array( |
|
| 335 | + $args['meta_query'] = array(array( |
|
| 336 | 336 | 'key' => '_course_woocommerce_product', |
| 337 | 337 | 'value' => $item_id |
| 338 | - ) ); |
|
| 338 | + )); |
|
| 339 | 339 | $args['orderby'] = 'menu_order date'; |
| 340 | 340 | $args['order'] = 'ASC'; |
| 341 | 341 | |
| 342 | 342 | // loop through courses |
| 343 | - $courses = get_posts( $args ); |
|
| 344 | - if( $courses && count( $courses ) > 0 ) { |
|
| 343 | + $courses = get_posts($args); |
|
| 344 | + if ($courses && count($courses) > 0) { |
|
| 345 | 345 | |
| 346 | - foreach( $courses as $course ) { |
|
| 346 | + foreach ($courses as $course) { |
|
| 347 | 347 | |
| 348 | 348 | $title = $course->post_title; |
| 349 | - $permalink = get_permalink( $course->ID ); |
|
| 350 | - $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 349 | + $permalink = get_permalink($course->ID); |
|
| 350 | + $course_links[] .= '<a href="'.esc_url($permalink).'" >'.$title.'</a> '; |
|
| 351 | 351 | |
| 352 | 352 | } // end for each |
| 353 | 353 | |
@@ -358,24 +358,24 @@ discard block |
||
| 358 | 358 | }// end loop through orders |
| 359 | 359 | |
| 360 | 360 | // add the courses to the WooCommerce notice |
| 361 | - if( ! empty( $course_links) ){ |
|
| 361 | + if ( ! empty($course_links)) { |
|
| 362 | 362 | |
| 363 | 363 | $courses_html = _nx( |
| 364 | 364 | 'You have purchased the following course:', |
| 365 | 365 | 'You have purchased the following courses:', |
| 366 | - count( $course_links ), |
|
| 366 | + count($course_links), |
|
| 367 | 367 | 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
| 368 | 368 | ); |
| 369 | 369 | |
| 370 | - foreach( $course_links as $link ){ |
|
| 370 | + foreach ($course_links as $link) { |
|
| 371 | 371 | |
| 372 | - $courses_html .= '<li>' . $link . '</li>'; |
|
| 372 | + $courses_html .= '<li>'.$link.'</li>'; |
|
| 373 | 373 | |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | $courses_html .= ' </ul>'; |
| 377 | 377 | |
| 378 | - wc_add_notice( $courses_html, 'success' ); |
|
| 378 | + wc_add_notice($courses_html, 'success'); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | } // end course_link_order_form |
@@ -388,20 +388,20 @@ discard block |
||
| 388 | 388 | * |
| 389 | 389 | * @since 1.9.0 |
| 390 | 390 | */ |
| 391 | - public static function course_in_cart_message(){ |
|
| 391 | + public static function course_in_cart_message() { |
|
| 392 | 392 | |
| 393 | 393 | global $post; |
| 394 | 394 | |
| 395 | - if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 395 | + if (self::is_course_in_cart($post->ID)) { ?> |
|
| 396 | 396 | |
| 397 | 397 | <div class="sensei-message info">' |
| 398 | 398 | <?php |
| 399 | 399 | |
| 400 | - $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 401 | - . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 402 | - . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 400 | + $cart_link = '<a class="cart-complete" href="'.WC()->cart->get_checkout_url() |
|
| 401 | + . '" title="'.__('complete purchase', 'woothemes-sensei').'">' |
|
| 402 | + . __('complete the purchase', 'woothemes-sensei').'</a>'; |
|
| 403 | 403 | |
| 404 | - sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 404 | + sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link); |
|
| 405 | 405 | |
| 406 | 406 | ?> |
| 407 | 407 | </div> |
@@ -415,14 +415,14 @@ discard block |
||
| 415 | 415 | * @param $course_id |
| 416 | 416 | * @return bool |
| 417 | 417 | */ |
| 418 | - public static function is_course_in_cart( $course_id ){ |
|
| 418 | + public static function is_course_in_cart($course_id) { |
|
| 419 | 419 | |
| 420 | - $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 421 | - $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 420 | + $wc_post_id = absint(get_post_meta($course_id, '_course_woocommerce_product', true)); |
|
| 421 | + $user_course_status_id = Sensei_Utils::user_started_course($course_id, get_current_user_id()); |
|
| 422 | 422 | |
| 423 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 423 | + if (0 < intval($wc_post_id) && ! $user_course_status_id) { |
|
| 424 | 424 | |
| 425 | - if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 425 | + if (self::is_product_in_cart($wc_post_id)) { |
|
| 426 | 426 | |
| 427 | 427 | return true; |
| 428 | 428 | |
@@ -440,20 +440,20 @@ discard block |
||
| 440 | 440 | * @param $product_id |
| 441 | 441 | * @return bool |
| 442 | 442 | */ |
| 443 | - public static function is_product_in_cart( $product_id ){ |
|
| 443 | + public static function is_product_in_cart($product_id) { |
|
| 444 | 444 | |
| 445 | - if ( 0 < $product_id ) { |
|
| 445 | + if (0 < $product_id) { |
|
| 446 | 446 | |
| 447 | - $product = wc_get_product( $product_id ); |
|
| 447 | + $product = wc_get_product($product_id); |
|
| 448 | 448 | |
| 449 | 449 | $parent_id = ''; |
| 450 | - if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 450 | + if (isset($product->variation_id) && 0 < intval($product->variation_id)) { |
|
| 451 | 451 | $wc_product_id = $product->parent->id; |
| 452 | 452 | } |
| 453 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 453 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 454 | 454 | |
| 455 | 455 | $cart_product = $values['data']; |
| 456 | - if( $product_id == $cart_product->id ) { |
|
| 456 | + if ($product_id == $cart_product->id) { |
|
| 457 | 457 | |
| 458 | 458 | return true; |
| 459 | 459 | |
@@ -475,9 +475,9 @@ discard block |
||
| 475 | 475 | * @type int $wp_post_id |
| 476 | 476 | * } |
| 477 | 477 | */ |
| 478 | - public static function get_free_product_ids(){ |
|
| 478 | + public static function get_free_product_ids() { |
|
| 479 | 479 | |
| 480 | - return get_posts( array( |
|
| 480 | + return get_posts(array( |
|
| 481 | 481 | 'post_type' => 'product', |
| 482 | 482 | 'posts_per_page' => '1000', |
| 483 | 483 | 'fields' => 'ids', |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | * @since 1.9.0 |
| 503 | 503 | * @return array $wp_meta_query_param |
| 504 | 504 | */ |
| 505 | - public static function get_free_courses_meta_query_args(){ |
|
| 505 | + public static function get_free_courses_meta_query_args() { |
|
| 506 | 506 | |
| 507 | 507 | return array( |
| 508 | 508 | 'relation' => 'OR', |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | * @since 1.9.0 |
| 527 | 527 | * @return array $wp_query_meta_query_args_param |
| 528 | 528 | */ |
| 529 | - public static function get_paid_courses_meta_query_args(){ |
|
| 529 | + public static function get_paid_courses_meta_query_args() { |
|
| 530 | 530 | |
| 531 | 531 | $paid_product_ids = self::get_paid_product_ids(); |
| 532 | 532 | |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | 'key' => '_course_woocommerce_product', |
| 536 | 536 | // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
| 537 | 537 | // query |
| 538 | - 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 538 | + 'value' => empty($paid_product_ids) ? '-1000' : $paid_product_ids, |
|
| 539 | 539 | 'compare' => 'IN', |
| 540 | 540 | ), |
| 541 | 541 | ); |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | * @since 1.9.0 |
| 550 | 550 | * @return array $product_query_args |
| 551 | 551 | */ |
| 552 | - public static function get_paid_products_on_sale_query_args(){ |
|
| 552 | + public static function get_paid_products_on_sale_query_args() { |
|
| 553 | 553 | |
| 554 | 554 | $args = array( |
| 555 | 555 | 'post_type' => 'product', |
@@ -559,9 +559,9 @@ discard block |
||
| 559 | 559 | 'suppress_filters' => 0 |
| 560 | 560 | ); |
| 561 | 561 | |
| 562 | - $args[ 'fields' ] = 'ids'; |
|
| 562 | + $args['fields'] = 'ids'; |
|
| 563 | 563 | |
| 564 | - $args[ 'meta_query' ] = array( |
|
| 564 | + $args['meta_query'] = array( |
|
| 565 | 565 | 'relation' => 'AND', |
| 566 | 566 | array( |
| 567 | 567 | 'key'=> '_regular_price', |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | * |
| 589 | 589 | * @return array |
| 590 | 590 | */ |
| 591 | - public static function get_paid_products_not_on_sale_query_args(){ |
|
| 591 | + public static function get_paid_products_not_on_sale_query_args() { |
|
| 592 | 592 | |
| 593 | 593 | $args = array( |
| 594 | 594 | 'post_type' => 'product', |
@@ -598,8 +598,8 @@ discard block |
||
| 598 | 598 | 'suppress_filters' => 0 |
| 599 | 599 | ); |
| 600 | 600 | |
| 601 | - $args[ 'fields' ] = 'ids'; |
|
| 602 | - $args[ 'meta_query' ] = array( |
|
| 601 | + $args['fields'] = 'ids'; |
|
| 602 | + $args['meta_query'] = array( |
|
| 603 | 603 | 'relation' => 'AND', |
| 604 | 604 | array( |
| 605 | 605 | 'key'=> '_regular_price', |
@@ -625,24 +625,24 @@ discard block |
||
| 625 | 625 | * |
| 626 | 626 | * @return array $woocommerce_paid_product_ids |
| 627 | 627 | */ |
| 628 | - public static function get_paid_product_ids(){ |
|
| 628 | + public static function get_paid_product_ids() { |
|
| 629 | 629 | |
| 630 | 630 | // get all the paid WooCommerce products that has regular |
| 631 | 631 | // and sale price greater than 0 |
| 632 | 632 | // will be used later to check for course with the id as meta |
| 633 | - $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 633 | + $paid_product_ids_with_sale = get_posts(self::get_paid_products_on_sale_query_args()); |
|
| 634 | 634 | |
| 635 | 635 | // get all the paid WooCommerce products that has regular price |
| 636 | 636 | // greater than 0 without a sale price |
| 637 | 637 | // will be used later to check for course with the id as meta |
| 638 | - $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 638 | + $paid_product_ids_without_sale = get_posts(self::get_paid_products_not_on_sale_query_args()); |
|
| 639 | 639 | |
| 640 | 640 | // combine products ID's with regular and sale price grater than zero and those without |
| 641 | 641 | // sale but regular price greater than zero |
| 642 | - $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 642 | + $woocommerce_paid_product_ids = array_merge($paid_product_ids_with_sale, $paid_product_ids_without_sale); |
|
| 643 | 643 | |
| 644 | 644 | // if |
| 645 | - if( empty($woocommerce_paid_product_ids) ){ |
|
| 645 | + if (empty($woocommerce_paid_product_ids)) { |
|
| 646 | 646 | return array( ); |
| 647 | 647 | } |
| 648 | 648 | return $woocommerce_paid_product_ids; |
@@ -661,20 +661,20 @@ discard block |
||
| 661 | 661 | * |
| 662 | 662 | * @return array |
| 663 | 663 | */ |
| 664 | - public static function get_free_courses(){ |
|
| 664 | + public static function get_free_courses() { |
|
| 665 | 665 | |
| 666 | 666 | $free_course_query_args = Sensei_Course::get_default_query_args(); |
| 667 | - $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 667 | + $free_course_query_args['meta_query'] = self::get_free_courses_meta_query_args(); |
|
| 668 | 668 | |
| 669 | 669 | // don't show any paid courses |
| 670 | 670 | $courses = self::get_paid_courses(); |
| 671 | 671 | $ids = array(); |
| 672 | - foreach( $courses as $course ){ |
|
| 672 | + foreach ($courses as $course) { |
|
| 673 | 673 | $ids[] = $course->ID; |
| 674 | 674 | } |
| 675 | - $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 675 | + $free_course_query_args['post__not_in'] = $ids; |
|
| 676 | 676 | |
| 677 | - return get_posts( $free_course_query_args ); |
|
| 677 | + return get_posts($free_course_query_args); |
|
| 678 | 678 | |
| 679 | 679 | } |
| 680 | 680 | |
@@ -684,13 +684,13 @@ discard block |
||
| 684 | 684 | * @since 1.9.0 |
| 685 | 685 | * @return array |
| 686 | 686 | */ |
| 687 | - public static function get_paid_courses(){ |
|
| 687 | + public static function get_paid_courses() { |
|
| 688 | 688 | |
| 689 | 689 | $paid_course_query_args = Sensei_Course::get_default_query_args(); |
| 690 | 690 | |
| 691 | - $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 691 | + $paid_course_query_args['meta_query'] = self::get_paid_courses_meta_query_args(); |
|
| 692 | 692 | |
| 693 | - return get_posts( $paid_course_query_args ); |
|
| 693 | + return get_posts($paid_course_query_args); |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | /** |
@@ -705,17 +705,17 @@ discard block |
||
| 705 | 705 | * @param int $course_id |
| 706 | 706 | * @return string $html markup for the button or nothing if user not allowed to buy |
| 707 | 707 | */ |
| 708 | - public static function the_add_to_cart_button_html( $course_id ){ |
|
| 708 | + public static function the_add_to_cart_button_html($course_id) { |
|
| 709 | 709 | |
| 710 | - if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
| 710 | + if ( ! Sensei_Course::is_prerequisite_complete($course_id)) { |
|
| 711 | 711 | return ''; |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 714 | + $wc_post_id = self::get_course_product_id($course_id); |
|
| 715 | 715 | |
| 716 | 716 | // Check if customer purchased the product |
| 717 | - if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 718 | - || empty( $wc_post_id ) ) { |
|
| 717 | + if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id) |
|
| 718 | + || empty($wc_post_id)) { |
|
| 719 | 719 | |
| 720 | 720 | return ''; |
| 721 | 721 | |
@@ -723,15 +723,15 @@ discard block |
||
| 723 | 723 | |
| 724 | 724 | // based on simple.php in WC templates/single-product/add-to-cart/ |
| 725 | 725 | // Get the product |
| 726 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 726 | + $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 727 | 727 | |
| 728 | 728 | // do not show the button for invalid products, non purchasable products, out |
| 729 | 729 | // of stock product or if course is already in cart |
| 730 | - if ( ! isset ( $product ) |
|
| 731 | - || ! is_object( $product ) |
|
| 730 | + if ( ! isset ($product) |
|
| 731 | + || ! is_object($product) |
|
| 732 | 732 | || ! $product->is_purchasable() |
| 733 | 733 | || ! $product->is_in_stock() |
| 734 | - || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 734 | + || self::is_course_in_cart($wc_post_id)) { |
|
| 735 | 735 | |
| 736 | 736 | return ''; |
| 737 | 737 | |
@@ -742,23 +742,23 @@ discard block |
||
| 742 | 742 | // |
| 743 | 743 | ?> |
| 744 | 744 | |
| 745 | - <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" |
|
| 745 | + <form action="<?php echo esc_url($product->add_to_cart_url()); ?>" |
|
| 746 | 746 | class="cart" |
| 747 | 747 | method="post" |
| 748 | 748 | enctype="multipart/form-data"> |
| 749 | 749 | |
| 750 | - <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" /> |
|
| 750 | + <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?>" /> |
|
| 751 | 751 | |
| 752 | 752 | <input type="hidden" name="quantity" value="1" /> |
| 753 | 753 | |
| 754 | - <?php if ( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { ?> |
|
| 754 | + <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?> |
|
| 755 | 755 | |
| 756 | 756 | <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?>" /> |
| 757 | - <?php if( isset( $product->variation_data ) && is_array( $product->variation_data ) && count( $product->variation_data ) > 0 ) { ?> |
|
| 757 | + <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?> |
|
| 758 | 758 | |
| 759 | - <?php foreach( $product->variation_data as $att => $val ) { ?> |
|
| 759 | + <?php foreach ($product->variation_data as $att => $val) { ?> |
|
| 760 | 760 | |
| 761 | - <input type="hidden" name="<?php echo esc_attr( $att ); ?>" id="<?php echo esc_attr( str_replace( 'attribute_', '', $att ) ); ?>" value="<?php echo esc_attr( $val ); ?>" /> |
|
| 761 | + <input type="hidden" name="<?php echo esc_attr($att); ?>" id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?>" value="<?php echo esc_attr($val); ?>" /> |
|
| 762 | 762 | |
| 763 | 763 | <?php } ?> |
| 764 | 764 | |
@@ -786,26 +786,26 @@ discard block |
||
| 786 | 786 | * |
| 787 | 787 | * @return string $message |
| 788 | 788 | */ |
| 789 | - public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 789 | + public static function alter_no_permissions_message($message, $post_id) { |
|
| 790 | 790 | |
| 791 | - if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 791 | + if (empty($post_id) || 'course' != get_post_type($post_id)) { |
|
| 792 | 792 | return $message; |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | - $product_id = self::get_course_product_id( $post_id ); |
|
| 795 | + $product_id = self::get_course_product_id($post_id); |
|
| 796 | 796 | |
| 797 | - if( ! $product_id |
|
| 798 | - || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 797 | + if ( ! $product_id |
|
| 798 | + || self::has_customer_bought_product(get_current_user_id(), $product_id)) { |
|
| 799 | 799 | |
| 800 | 800 | return $message; |
| 801 | 801 | |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | ob_start(); |
| 805 | - self::the_course_no_permissions_message( $post_id ); |
|
| 805 | + self::the_course_no_permissions_message($post_id); |
|
| 806 | 806 | $woocommerce_course_no_permissions_message = ob_get_clean(); |
| 807 | 807 | |
| 808 | - return $woocommerce_course_no_permissions_message ; |
|
| 808 | + return $woocommerce_course_no_permissions_message; |
|
| 809 | 809 | |
| 810 | 810 | } |
| 811 | 811 | /** |
@@ -814,16 +814,16 @@ discard block |
||
| 814 | 814 | * |
| 815 | 815 | * @since 1.9.0 |
| 816 | 816 | */ |
| 817 | - public static function the_course_no_permissions_message( $course_id ){ |
|
| 817 | + public static function the_course_no_permissions_message($course_id) { |
|
| 818 | 818 | |
| 819 | 819 | // login link |
| 820 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 821 | - $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 820 | + $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']); |
|
| 821 | + $login_link = '<a href="'.esc_url(get_permalink($my_courses_page_id)).'">'.__('log in', 'woothemes-sensei').'</a>'; |
|
| 822 | 822 | |
| 823 | 823 | ?> |
| 824 | 824 | |
| 825 | 825 | <span class="add-to-cart-login"> |
| 826 | - <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?> |
|
| 826 | + <?php echo sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link); ?> |
|
| 827 | 827 | </span> |
| 828 | 828 | |
| 829 | 829 | <?php } |
@@ -838,43 +838,43 @@ discard block |
||
| 838 | 838 | * |
| 839 | 839 | * @return bool |
| 840 | 840 | */ |
| 841 | - public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 841 | + public static function has_customer_bought_product($user_id, $product_id) { |
|
| 842 | 842 | |
| 843 | - $orders = get_posts( array( |
|
| 843 | + $orders = get_posts(array( |
|
| 844 | 844 | 'posts_per_page' => -1, |
| 845 | 845 | 'meta_key' => '_customer_user', |
| 846 | - 'meta_value' => intval( $user_id ), |
|
| 846 | + 'meta_value' => intval($user_id), |
|
| 847 | 847 | 'post_type' => 'shop_order', |
| 848 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 849 | - ) ); |
|
| 848 | + 'post_status' => array('wc-processing', 'wc-completed'), |
|
| 849 | + )); |
|
| 850 | 850 | |
| 851 | - foreach ( $orders as $order_id ) { |
|
| 851 | + foreach ($orders as $order_id) { |
|
| 852 | 852 | |
| 853 | - $order = new WC_Order( $order_id->ID ); |
|
| 853 | + $order = new WC_Order($order_id->ID); |
|
| 854 | 854 | |
| 855 | - if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
| 855 | + if ($order->post_status != 'wc-completed' && $order->post_status != 'wc-processing') { |
|
| 856 | 856 | |
| 857 | 857 | continue; |
| 858 | 858 | } |
| 859 | 859 | |
| 860 | - if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
| 860 | + if ( ! (0 < sizeof($order->get_items()))) { |
|
| 861 | 861 | |
| 862 | 862 | continue; |
| 863 | 863 | |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | - foreach( $order->get_items() as $item ) { |
|
| 866 | + foreach ($order->get_items() as $item) { |
|
| 867 | 867 | |
| 868 | 868 | // Check if user has bought product |
| 869 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 869 | + if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) { |
|
| 870 | 870 | |
| 871 | 871 | // Check if user has an active subscription for product |
| 872 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 873 | - $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
| 874 | - if( $sub_key ) { |
|
| 875 | - $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
| 876 | - if( $sub && isset( $sub['status'] ) ) { |
|
| 877 | - if( 'active' == $sub['status'] ) { |
|
| 872 | + if (class_exists('WC_Subscriptions_Manager')) { |
|
| 873 | + $sub_key = WC_Subscriptions_Manager::get_subscription_key($order_id->ID, $product_id); |
|
| 874 | + if ($sub_key) { |
|
| 875 | + $sub = WC_Subscriptions_Manager::get_subscription($sub_key); |
|
| 876 | + if ($sub && isset($sub['status'])) { |
|
| 877 | + if ('active' == $sub['status']) { |
|
| 878 | 878 | return true; |
| 879 | 879 | } else { |
| 880 | 880 | return false; |
@@ -903,11 +903,11 @@ discard block |
||
| 903 | 903 | * @return string $woocommerce_product_id or false if none exist |
| 904 | 904 | * |
| 905 | 905 | */ |
| 906 | - public static function get_course_product_id( $course_id ){ |
|
| 906 | + public static function get_course_product_id($course_id) { |
|
| 907 | 907 | |
| 908 | - $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 908 | + $product_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
| 909 | 909 | |
| 910 | - if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 910 | + if (empty($product_id) || 'product' != get_post_type($product_id)) { |
|
| 911 | 911 | return false; |
| 912 | 912 | } |
| 913 | 913 | |
@@ -921,11 +921,11 @@ discard block |
||
| 921 | 921 | * @param array $classes |
| 922 | 922 | * @return array |
| 923 | 923 | */ |
| 924 | - public static function add_woocommerce_body_class( $classes ){ |
|
| 924 | + public static function add_woocommerce_body_class($classes) { |
|
| 925 | 925 | |
| 926 | - if( ! in_array( 'woocommerce', $classes ) ){ |
|
| 926 | + if ( ! in_array('woocommerce', $classes)) { |
|
| 927 | 927 | |
| 928 | - $classes[] ='woocommerce'; |
|
| 928 | + $classes[] = 'woocommerce'; |
|
| 929 | 929 | |
| 930 | 930 | } |
| 931 | 931 | |
@@ -206,13 +206,13 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * Generates content for a single row of the table in the user management |
| 209 | - * screen. |
|
| 210 | - * |
|
| 209 | + * screen. |
|
| 210 | + * |
|
| 211 | 211 | * @since 1.7.0 |
| 212 | - * |
|
| 212 | + * |
|
| 213 | 213 | * @param object $item The current item |
| 214 | - * |
|
| 215 | - * @return void |
|
| 214 | + * |
|
| 215 | + * @return void |
|
| 216 | 216 | */ |
| 217 | 217 | protected function get_row_data( $item ) { |
| 218 | 218 | global $wp_version; |
@@ -220,8 +220,8 @@ discard block |
||
| 220 | 220 | switch ( $this->view ) { |
| 221 | 221 | case 'learners' : |
| 222 | 222 | |
| 223 | - // in this case the item passed in is actually the users activity on course of lesson |
|
| 224 | - $user_activity = $item; |
|
| 223 | + // in this case the item passed in is actually the users activity on course of lesson |
|
| 224 | + $user_activity = $item; |
|
| 225 | 225 | $post_id = false; |
| 226 | 226 | |
| 227 | 227 | if( $this->lesson_id ) { |
@@ -240,45 +240,45 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | if( 'complete' == $user_activity->comment_approved || 'graded' == $user_activity->comment_approved || 'passed' == $user_activity->comment_approved ) { |
| 242 | 242 | |
| 243 | - $status_html = '<span class="graded">' .__( 'Completed', 'woothemes-sensei' ) . '</span>'; |
|
| 243 | + $status_html = '<span class="graded">' .__( 'Completed', 'woothemes-sensei' ) . '</span>'; |
|
| 244 | 244 | |
| 245 | 245 | } else { |
| 246 | 246 | |
| 247 | - $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>'; |
|
| 247 | + $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>'; |
|
| 248 | 248 | |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - $title = Sensei()->learners->get_learner_full_name( $user_activity->user_id ); |
|
| 251 | + $title = Sensei()->learners->get_learner_full_name( $user_activity->user_id ); |
|
| 252 | 252 | $a_title = sprintf( __( 'Edit “%s”' ), $title ); |
| 253 | 253 | |
| 254 | - // get the learners order for this course if the course was purchased |
|
| 254 | + // get the learners order for this course if the course was purchased |
|
| 255 | 255 | |
| 256 | - $course_order_id_attribute = ''; |
|
| 257 | - if( Sensei_WC::is_woocommerce_active() ){ |
|
| 256 | + $course_order_id_attribute = ''; |
|
| 257 | + if( Sensei_WC::is_woocommerce_active() ){ |
|
| 258 | 258 | |
| 259 | - $course_product_order_id = Sensei_WC::get_learner_course_active_order_id( $user_activity->user_id, $post_id ); |
|
| 259 | + $course_product_order_id = Sensei_WC::get_learner_course_active_order_id( $user_activity->user_id, $post_id ); |
|
| 260 | 260 | |
| 261 | - if( $course_product_order_id ){ |
|
| 261 | + if( $course_product_order_id ){ |
|
| 262 | 262 | |
| 263 | - $course_order_id_attribute = ' data-order_id="' . $course_product_order_id . '" '; |
|
| 263 | + $course_order_id_attribute = ' data-order_id="' . $course_product_order_id . '" '; |
|
| 264 | 264 | |
| 265 | - } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - } |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * sensei_learners_main_column_data filter |
|
| 271 | - * |
|
| 272 | - * This filter runs on the learner management screen for a specific course. |
|
| 273 | - * It provides the learner row column details. |
|
| 274 | - * |
|
| 275 | - * @param array $columns{ |
|
| 276 | - * type string $title |
|
| 277 | - * type string $date_started |
|
| 278 | - * type string $course_status (completed, started etc) |
|
| 279 | - * type html $action_buttons |
|
| 280 | - * } |
|
| 281 | - */ |
|
| 269 | + /** |
|
| 270 | + * sensei_learners_main_column_data filter |
|
| 271 | + * |
|
| 272 | + * This filter runs on the learner management screen for a specific course. |
|
| 273 | + * It provides the learner row column details. |
|
| 274 | + * |
|
| 275 | + * @param array $columns{ |
|
| 276 | + * type string $title |
|
| 277 | + * type string $date_started |
|
| 278 | + * type string $course_status (completed, started etc) |
|
| 279 | + * type html $action_buttons |
|
| 280 | + * } |
|
| 281 | + */ |
|
| 282 | 282 | $column_data = apply_filters( 'sensei_learners_main_column_data', array( |
| 283 | 283 | 'title' => '<strong><a class="row-title" href="' . admin_url( 'user-edit.php?user_id=' . $user_activity->user_id ) . '" title="' . esc_attr( $a_title ) . '">' . $title . '</a></strong>', |
| 284 | 284 | 'date_started' => get_comment_meta( $user_activity->comment_ID, 'start', true), |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | |
| 309 | 309 | case 'courses' : |
| 310 | 310 | default: |
| 311 | - $course_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_course_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any' ) ) ); |
|
| 311 | + $course_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_course_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any' ) ) ); |
|
| 312 | 312 | $title = get_the_title( $item ); |
| 313 | 313 | $a_title = sprintf( __( 'Edit “%s”' ), $title ); |
| 314 | 314 | |
@@ -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 Learners Overview List Table Class |
@@ -23,28 +23,28 @@ discard block |
||
| 23 | 23 | * @since 1.6.0 |
| 24 | 24 | * @return void |
| 25 | 25 | */ |
| 26 | - public function __construct ( $course_id = 0, $lesson_id = 0 ) { |
|
| 27 | - $this->course_id = intval( $course_id ); |
|
| 28 | - $this->lesson_id = intval( $lesson_id ); |
|
| 26 | + public function __construct($course_id = 0, $lesson_id = 0) { |
|
| 27 | + $this->course_id = intval($course_id); |
|
| 28 | + $this->lesson_id = intval($lesson_id); |
|
| 29 | 29 | |
| 30 | - if( isset( $_GET['view'] ) && in_array( $_GET['view'], array( 'courses', 'lessons', 'learners' ) ) ) { |
|
| 30 | + if (isset($_GET['view']) && in_array($_GET['view'], array('courses', 'lessons', 'learners'))) { |
|
| 31 | 31 | $this->view = $_GET['view']; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | // Viewing a single lesson always sets the view to Learners |
| 35 | - if( $this->lesson_id ) { |
|
| 35 | + if ($this->lesson_id) { |
|
| 36 | 36 | $this->view = 'learners'; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | // Load Parent token into constructor |
| 40 | - parent::__construct( 'learners_main' ); |
|
| 40 | + parent::__construct('learners_main'); |
|
| 41 | 41 | |
| 42 | 42 | // Actions |
| 43 | - add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) ); |
|
| 44 | - add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) ); |
|
| 45 | - add_action( 'sensei_learners_extra', array( $this, 'add_learners_box' ) ); |
|
| 43 | + add_action('sensei_before_list_table', array($this, 'data_table_header')); |
|
| 44 | + add_action('sensei_after_list_table', array($this, 'data_table_footer')); |
|
| 45 | + add_action('sensei_learners_extra', array($this, 'add_learners_box')); |
|
| 46 | 46 | |
| 47 | - add_filter( 'sensei_list_table_search_button_text', array( $this, 'search_button' ) ); |
|
| 47 | + add_filter('sensei_list_table_search_button_text', array($this, 'search_button')); |
|
| 48 | 48 | } // End __construct() |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -54,38 +54,38 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | function get_columns() { |
| 56 | 56 | $columns = array(); |
| 57 | - switch( $this->view ) { |
|
| 57 | + switch ($this->view) { |
|
| 58 | 58 | case 'learners': |
| 59 | 59 | $columns = array( |
| 60 | - 'title' => __( 'Learner', 'woothemes-sensei' ), |
|
| 61 | - 'date_started' => __( 'Date Started', 'woothemes-sensei' ), |
|
| 62 | - 'user_status' => __( 'Status', 'woothemes-sensei' ), |
|
| 60 | + 'title' => __('Learner', 'woothemes-sensei'), |
|
| 61 | + 'date_started' => __('Date Started', 'woothemes-sensei'), |
|
| 62 | + 'user_status' => __('Status', 'woothemes-sensei'), |
|
| 63 | 63 | ); |
| 64 | 64 | break; |
| 65 | 65 | |
| 66 | 66 | case 'lessons': |
| 67 | 67 | $columns = array( |
| 68 | - 'title' => __( 'Lesson', 'woothemes-sensei' ), |
|
| 69 | - 'num_learners' => __( '# Learners', 'woothemes-sensei' ), |
|
| 70 | - 'updated' => __( 'Last Updated', 'woothemes-sensei' ), |
|
| 68 | + 'title' => __('Lesson', 'woothemes-sensei'), |
|
| 69 | + 'num_learners' => __('# Learners', 'woothemes-sensei'), |
|
| 70 | + 'updated' => __('Last Updated', 'woothemes-sensei'), |
|
| 71 | 71 | ); |
| 72 | 72 | break; |
| 73 | 73 | |
| 74 | 74 | case 'courses': |
| 75 | 75 | default: |
| 76 | 76 | $columns = array( |
| 77 | - 'title' => __( 'Course', 'woothemes-sensei' ), |
|
| 78 | - 'num_learners' => __( '# Learners', 'woothemes-sensei' ), |
|
| 79 | - 'updated' => __( 'Last Updated', 'woothemes-sensei' ), |
|
| 77 | + 'title' => __('Course', 'woothemes-sensei'), |
|
| 78 | + 'num_learners' => __('# Learners', 'woothemes-sensei'), |
|
| 79 | + 'updated' => __('Last Updated', 'woothemes-sensei'), |
|
| 80 | 80 | ); |
| 81 | 81 | break; |
| 82 | 82 | } |
| 83 | 83 | $columns['actions'] = ''; |
| 84 | 84 | // Backwards compatible |
| 85 | - if ( 'learners' == $this->view ) { |
|
| 86 | - $columns = apply_filters( 'sensei_learners_learners_columns', $columns, $this ); |
|
| 85 | + if ('learners' == $this->view) { |
|
| 86 | + $columns = apply_filters('sensei_learners_learners_columns', $columns, $this); |
|
| 87 | 87 | } |
| 88 | - $columns = apply_filters( 'sensei_learners_default_columns', $columns, $this ); |
|
| 88 | + $columns = apply_filters('sensei_learners_default_columns', $columns, $this); |
|
| 89 | 89 | return $columns; |
| 90 | 90 | } |
| 91 | 91 | |
@@ -96,32 +96,32 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | function get_sortable_columns() { |
| 98 | 98 | $columns = array(); |
| 99 | - switch( $this->view ) { |
|
| 99 | + switch ($this->view) { |
|
| 100 | 100 | case 'learners': |
| 101 | 101 | $columns = array( |
| 102 | - 'title' => array( 'title', false ), |
|
| 102 | + 'title' => array('title', false), |
|
| 103 | 103 | ); |
| 104 | 104 | break; |
| 105 | 105 | |
| 106 | 106 | case 'lessons': |
| 107 | 107 | $columns = array( |
| 108 | - 'title' => array( 'title', false ), |
|
| 109 | - 'updated' => array( 'post_modified', false ), |
|
| 108 | + 'title' => array('title', false), |
|
| 109 | + 'updated' => array('post_modified', false), |
|
| 110 | 110 | ); |
| 111 | 111 | break; |
| 112 | 112 | |
| 113 | 113 | default: |
| 114 | 114 | $columns = array( |
| 115 | - 'title' => array( 'title', false ), |
|
| 116 | - 'updated' => array( 'post_modified', false ), |
|
| 115 | + 'title' => array('title', false), |
|
| 116 | + 'updated' => array('post_modified', false), |
|
| 117 | 117 | ); |
| 118 | 118 | break; |
| 119 | 119 | } |
| 120 | 120 | // Backwards compatible |
| 121 | - if ( 'learners' == $this->view ) { |
|
| 122 | - $columns = apply_filters( 'sensei_learners_learners_columns_sortable', $columns, $this ); |
|
| 121 | + if ('learners' == $this->view) { |
|
| 122 | + $columns = apply_filters('sensei_learners_learners_columns_sortable', $columns, $this); |
|
| 123 | 123 | } |
| 124 | - $columns = apply_filters( 'sensei_learners_default_columns_sortable', $columns, $this ); |
|
| 124 | + $columns = apply_filters('sensei_learners_default_columns_sortable', $columns, $this); |
|
| 125 | 125 | return $columns; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -135,72 +135,72 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | // Handle orderby |
| 137 | 137 | $orderby = ''; |
| 138 | - if ( !empty( $_GET['orderby'] ) ) { |
|
| 139 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
| 140 | - $orderby = esc_html( $_GET['orderby'] ); |
|
| 138 | + if ( ! empty($_GET['orderby'])) { |
|
| 139 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
| 140 | + $orderby = esc_html($_GET['orderby']); |
|
| 141 | 141 | } // End If Statement |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // Handle order |
| 145 | 145 | $order = 'DESC'; |
| 146 | - if ( !empty( $_GET['order'] ) ) { |
|
| 147 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
| 146 | + if ( ! empty($_GET['order'])) { |
|
| 147 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | // Handle category selection |
| 151 | 151 | $category = false; |
| 152 | - if ( !empty( $_GET['course_cat'] ) ) { |
|
| 153 | - $category = intval( $_GET['course_cat'] ); |
|
| 152 | + if ( ! empty($_GET['course_cat'])) { |
|
| 153 | + $category = intval($_GET['course_cat']); |
|
| 154 | 154 | } // End If Statement |
| 155 | 155 | |
| 156 | 156 | // Handle search |
| 157 | 157 | $search = false; |
| 158 | - if ( !empty( $_GET['s'] ) ) { |
|
| 159 | - $search = esc_html( $_GET['s'] ); |
|
| 158 | + if ( ! empty($_GET['s'])) { |
|
| 159 | + $search = esc_html($_GET['s']); |
|
| 160 | 160 | } // End If Statement |
| 161 | 161 | |
| 162 | - $per_page = $this->get_items_per_page( 'sensei_comments_per_page' ); |
|
| 163 | - $per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' ); |
|
| 162 | + $per_page = $this->get_items_per_page('sensei_comments_per_page'); |
|
| 163 | + $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); |
|
| 164 | 164 | |
| 165 | 165 | $paged = $this->get_pagenum(); |
| 166 | 166 | $offset = 0; |
| 167 | - if ( !empty($paged) ) { |
|
| 168 | - $offset = $per_page * ( $paged - 1 ); |
|
| 167 | + if ( ! empty($paged)) { |
|
| 168 | + $offset = $per_page * ($paged - 1); |
|
| 169 | 169 | } // End If Statement |
| 170 | 170 | |
| 171 | - switch( $this->view ) { |
|
| 171 | + switch ($this->view) { |
|
| 172 | 172 | case 'learners': |
| 173 | - if ( empty($orderby) ) { |
|
| 173 | + if (empty($orderby)) { |
|
| 174 | 174 | $orderby = ''; |
| 175 | 175 | } |
| 176 | - $this->items = $this->get_learners( compact( 'per_page', 'offset', 'orderby', 'order', 'search' ) ); |
|
| 176 | + $this->items = $this->get_learners(compact('per_page', 'offset', 'orderby', 'order', 'search')); |
|
| 177 | 177 | |
| 178 | 178 | break; |
| 179 | 179 | |
| 180 | 180 | case 'lessons': |
| 181 | - if ( empty($orderby) ) { |
|
| 181 | + if (empty($orderby)) { |
|
| 182 | 182 | $orderby = 'post_modified'; |
| 183 | 183 | } |
| 184 | - $this->items = $this->get_lessons( compact( 'per_page', 'offset', 'orderby', 'order', 'search' ) ); |
|
| 184 | + $this->items = $this->get_lessons(compact('per_page', 'offset', 'orderby', 'order', 'search')); |
|
| 185 | 185 | |
| 186 | 186 | break; |
| 187 | 187 | |
| 188 | 188 | default: |
| 189 | - if ( empty($orderby) ) { |
|
| 189 | + if (empty($orderby)) { |
|
| 190 | 190 | $orderby = 'post_modified'; |
| 191 | 191 | } |
| 192 | - $this->items = $this->get_courses( compact( 'per_page', 'offset', 'orderby', 'order', 'category', 'search' ) ); |
|
| 192 | + $this->items = $this->get_courses(compact('per_page', 'offset', 'orderby', 'order', 'category', 'search')); |
|
| 193 | 193 | |
| 194 | 194 | break; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | $total_items = $this->total_items; |
| 198 | - $total_pages = ceil( $total_items / $per_page ); |
|
| 199 | - $this->set_pagination_args( array( |
|
| 198 | + $total_pages = ceil($total_items / $per_page); |
|
| 199 | + $this->set_pagination_args(array( |
|
| 200 | 200 | 'total_items' => $total_items, |
| 201 | 201 | 'total_pages' => $total_pages, |
| 202 | 202 | 'per_page' => $per_page |
| 203 | - ) ); |
|
| 203 | + )); |
|
| 204 | 204 | |
| 205 | 205 | } // End prepare_items() |
| 206 | 206 | |
@@ -214,53 +214,53 @@ discard block |
||
| 214 | 214 | * |
| 215 | 215 | * @return void |
| 216 | 216 | */ |
| 217 | - protected function get_row_data( $item ) { |
|
| 217 | + protected function get_row_data($item) { |
|
| 218 | 218 | global $wp_version; |
| 219 | 219 | |
| 220 | - switch ( $this->view ) { |
|
| 220 | + switch ($this->view) { |
|
| 221 | 221 | case 'learners' : |
| 222 | 222 | |
| 223 | 223 | // in this case the item passed in is actually the users activity on course of lesson |
| 224 | 224 | $user_activity = $item; |
| 225 | 225 | $post_id = false; |
| 226 | 226 | |
| 227 | - if( $this->lesson_id ) { |
|
| 227 | + if ($this->lesson_id) { |
|
| 228 | 228 | |
| 229 | - $post_id = intval( $this->lesson_id ); |
|
| 230 | - $object_type = __( 'lesson', 'woothemes-sensei' ); |
|
| 229 | + $post_id = intval($this->lesson_id); |
|
| 230 | + $object_type = __('lesson', 'woothemes-sensei'); |
|
| 231 | 231 | $post_type = 'lesson'; |
| 232 | 232 | |
| 233 | - } elseif( $this->course_id ) { |
|
| 233 | + } elseif ($this->course_id) { |
|
| 234 | 234 | |
| 235 | - $post_id = intval( $this->course_id ); |
|
| 236 | - $object_type = __( 'course', 'woothemes-sensei' ); |
|
| 235 | + $post_id = intval($this->course_id); |
|
| 236 | + $object_type = __('course', 'woothemes-sensei'); |
|
| 237 | 237 | $post_type = 'course'; |
| 238 | 238 | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if( 'complete' == $user_activity->comment_approved || 'graded' == $user_activity->comment_approved || 'passed' == $user_activity->comment_approved ) { |
|
| 241 | + if ('complete' == $user_activity->comment_approved || 'graded' == $user_activity->comment_approved || 'passed' == $user_activity->comment_approved) { |
|
| 242 | 242 | |
| 243 | - $status_html = '<span class="graded">' .__( 'Completed', 'woothemes-sensei' ) . '</span>'; |
|
| 243 | + $status_html = '<span class="graded">'.__('Completed', 'woothemes-sensei').'</span>'; |
|
| 244 | 244 | |
| 245 | 245 | } else { |
| 246 | 246 | |
| 247 | - $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>'; |
|
| 247 | + $status_html = '<span class="in-progress">'.__('In Progress', 'woothemes-sensei').'</span>'; |
|
| 248 | 248 | |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - $title = Sensei()->learners->get_learner_full_name( $user_activity->user_id ); |
|
| 252 | - $a_title = sprintf( __( 'Edit “%s”' ), $title ); |
|
| 251 | + $title = Sensei()->learners->get_learner_full_name($user_activity->user_id); |
|
| 252 | + $a_title = sprintf(__('Edit “%s”'), $title); |
|
| 253 | 253 | |
| 254 | 254 | // get the learners order for this course if the course was purchased |
| 255 | 255 | |
| 256 | 256 | $course_order_id_attribute = ''; |
| 257 | - if( Sensei_WC::is_woocommerce_active() ){ |
|
| 257 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 258 | 258 | |
| 259 | - $course_product_order_id = Sensei_WC::get_learner_course_active_order_id( $user_activity->user_id, $post_id ); |
|
| 259 | + $course_product_order_id = Sensei_WC::get_learner_course_active_order_id($user_activity->user_id, $post_id); |
|
| 260 | 260 | |
| 261 | - if( $course_product_order_id ){ |
|
| 261 | + if ($course_product_order_id) { |
|
| 262 | 262 | |
| 263 | - $course_order_id_attribute = ' data-order_id="' . $course_product_order_id . '" '; |
|
| 263 | + $course_order_id_attribute = ' data-order_id="'.$course_product_order_id.'" '; |
|
| 264 | 264 | |
| 265 | 265 | } |
| 266 | 266 | |
@@ -279,50 +279,50 @@ discard block |
||
| 279 | 279 | * type html $action_buttons |
| 280 | 280 | * } |
| 281 | 281 | */ |
| 282 | - $column_data = apply_filters( 'sensei_learners_main_column_data', array( |
|
| 283 | - 'title' => '<strong><a class="row-title" href="' . admin_url( 'user-edit.php?user_id=' . $user_activity->user_id ) . '" title="' . esc_attr( $a_title ) . '">' . $title . '</a></strong>', |
|
| 284 | - 'date_started' => get_comment_meta( $user_activity->comment_ID, 'start', true), |
|
| 282 | + $column_data = apply_filters('sensei_learners_main_column_data', array( |
|
| 283 | + 'title' => '<strong><a class="row-title" href="'.admin_url('user-edit.php?user_id='.$user_activity->user_id).'" title="'.esc_attr($a_title).'">'.$title.'</a></strong>', |
|
| 284 | + 'date_started' => get_comment_meta($user_activity->comment_ID, 'start', true), |
|
| 285 | 285 | 'user_status' => $status_html, |
| 286 | - 'actions' => '<a class="remove-learner button" data-user_id="' . $user_activity->user_id . '" data-post_id="' . $post_id . '" data-post_type="' . $post_type . '" '. $course_order_id_attribute . '">' . sprintf( __( 'Remove from %1$s', 'woothemes-sensei' ), $object_type ) . '</a>', |
|
| 287 | - ), $item, $post_id, $post_type ); |
|
| 286 | + 'actions' => '<a class="remove-learner button" data-user_id="'.$user_activity->user_id.'" data-post_id="'.$post_id.'" data-post_type="'.$post_type.'" '.$course_order_id_attribute.'">'.sprintf(__('Remove from %1$s', 'woothemes-sensei'), $object_type).'</a>', |
|
| 287 | + ), $item, $post_id, $post_type); |
|
| 288 | 288 | |
| 289 | 289 | break; |
| 290 | 290 | |
| 291 | 291 | case 'lessons' : |
| 292 | - $lesson_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_lesson_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_lesson_status', 'status' => 'any' ) ) ); |
|
| 293 | - $title = get_the_title( $item ); |
|
| 294 | - $a_title = sprintf( __( 'Edit “%s”' ), $title ); |
|
| 292 | + $lesson_learners = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_learners_lesson_learners', array('post_id' => $item->ID, 'type' => 'sensei_lesson_status', 'status' => 'any'))); |
|
| 293 | + $title = get_the_title($item); |
|
| 294 | + $a_title = sprintf(__('Edit “%s”'), $title); |
|
| 295 | 295 | |
| 296 | 296 | $grading_action = ''; |
| 297 | - if ( get_post_meta( $item->ID, '_quiz_has_questions', true ) ) { |
|
| 298 | - $grading_action = ' <a class="button" href="' . esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'lesson_id' => $item->ID, 'course_id' => $this->course_id ), admin_url( 'admin.php' ) ) ) . '">' . __( 'Grading', 'woothemes-sensei' ) . '</a>'; |
|
| 297 | + if (get_post_meta($item->ID, '_quiz_has_questions', true)) { |
|
| 298 | + $grading_action = ' <a class="button" href="'.esc_url(add_query_arg(array('page' => 'sensei_grading', 'lesson_id' => $item->ID, 'course_id' => $this->course_id), admin_url('admin.php'))).'">'.__('Grading', 'woothemes-sensei').'</a>'; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - $column_data = apply_filters( 'sensei_learners_main_column_data', array( |
|
| 302 | - 'title' => '<strong><a class="row-title" href="' . admin_url( 'post.php?action=edit&post=' . $item->ID ) . '" title="' . esc_attr( $a_title ) . '">' . $title . '</a></strong>', |
|
| 301 | + $column_data = apply_filters('sensei_learners_main_column_data', array( |
|
| 302 | + 'title' => '<strong><a class="row-title" href="'.admin_url('post.php?action=edit&post='.$item->ID).'" title="'.esc_attr($a_title).'">'.$title.'</a></strong>', |
|
| 303 | 303 | 'num_learners' => $lesson_learners, |
| 304 | 304 | 'updated' => $item->post_modified, |
| 305 | - 'actions' => '<a class="button" href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID, 'course_id' => $this->course_id, 'view' => 'learners' ), admin_url( 'admin.php' ) ) ) . '">' . __( 'Manage learners', 'woothemes-sensei' ) . '</a> ' . $grading_action, |
|
| 306 | - ), $item, $this->course_id ); |
|
| 305 | + 'actions' => '<a class="button" href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID, 'course_id' => $this->course_id, 'view' => 'learners'), admin_url('admin.php'))).'">'.__('Manage learners', 'woothemes-sensei').'</a> '.$grading_action, |
|
| 306 | + ), $item, $this->course_id); |
|
| 307 | 307 | break; |
| 308 | 308 | |
| 309 | 309 | case 'courses' : |
| 310 | 310 | default: |
| 311 | - $course_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_course_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any' ) ) ); |
|
| 312 | - $title = get_the_title( $item ); |
|
| 313 | - $a_title = sprintf( __( 'Edit “%s”' ), $title ); |
|
| 311 | + $course_learners = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_learners_course_learners', array('post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any'))); |
|
| 312 | + $title = get_the_title($item); |
|
| 313 | + $a_title = sprintf(__('Edit “%s”'), $title); |
|
| 314 | 314 | |
| 315 | 315 | $grading_action = ''; |
| 316 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 317 | - $grading_action = ' <a class="button" href="' . esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $item->ID ), admin_url( 'admin.php' ) ) ) . '">' . __( 'Grading', 'woothemes-sensei' ) . '</a>'; |
|
| 316 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 317 | + $grading_action = ' <a class="button" href="'.esc_url(add_query_arg(array('page' => 'sensei_grading', 'course_id' => $item->ID), admin_url('admin.php'))).'">'.__('Grading', 'woothemes-sensei').'</a>'; |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - $column_data = apply_filters( 'sensei_learners_main_column_data', array( |
|
| 321 | - 'title' => '<strong><a class="row-title" href="' . admin_url( 'post.php?action=edit&post=' . $item->ID ) . '" title="' . esc_attr( $a_title ) . '">' . $title . '</a></strong>', |
|
| 320 | + $column_data = apply_filters('sensei_learners_main_column_data', array( |
|
| 321 | + 'title' => '<strong><a class="row-title" href="'.admin_url('post.php?action=edit&post='.$item->ID).'" title="'.esc_attr($a_title).'">'.$title.'</a></strong>', |
|
| 322 | 322 | 'num_learners' => $course_learners, |
| 323 | 323 | 'updated' => $item->post_modified, |
| 324 | - 'actions' => '<a class="button" href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $item->ID, 'view' => 'learners' ), admin_url( 'admin.php' ) ) ) . '">' . __( 'Manage learners', 'woothemes-sensei' ) . '</a> ' . $grading_action, |
|
| 325 | - ), $item ); |
|
| 324 | + 'actions' => '<a class="button" href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'course_id' => $item->ID, 'view' => 'learners'), admin_url('admin.php'))).'">'.__('Manage learners', 'woothemes-sensei').'</a> '.$grading_action, |
|
| 325 | + ), $item); |
|
| 326 | 326 | |
| 327 | 327 | break; |
| 328 | 328 | } // switch |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | * @since 1.7.0 |
| 336 | 336 | * @return array courses |
| 337 | 337 | */ |
| 338 | - private function get_courses( $args ) { |
|
| 338 | + private function get_courses($args) { |
|
| 339 | 339 | $course_args = array( |
| 340 | 340 | 'post_type' => 'course', |
| 341 | 341 | 'post_status' => 'publish', |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | 'order' => $args['order'], |
| 346 | 346 | ); |
| 347 | 347 | |
| 348 | - if( $args['category'] ) { |
|
| 348 | + if ($args['category']) { |
|
| 349 | 349 | $course_args['tax_query'][] = array( |
| 350 | 350 | 'taxonomy' => 'course-category', |
| 351 | 351 | 'field' => 'id', |
@@ -353,11 +353,11 @@ discard block |
||
| 353 | 353 | ); |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | - if( $args['search'] ) { |
|
| 356 | + if ($args['search']) { |
|
| 357 | 357 | $course_args['s'] = $args['search']; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - $courses_query = new WP_Query( apply_filters( 'sensei_learners_filter_courses', $course_args ) ); |
|
| 360 | + $courses_query = new WP_Query(apply_filters('sensei_learners_filter_courses', $course_args)); |
|
| 361 | 361 | |
| 362 | 362 | $this->total_items = $courses_query->found_posts; |
| 363 | 363 | return $courses_query->posts; |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * @since 1.7.0 |
| 369 | 369 | * @return array lessons |
| 370 | 370 | */ |
| 371 | - private function get_lessons( $args ) { |
|
| 371 | + private function get_lessons($args) { |
|
| 372 | 372 | $lesson_args = array( |
| 373 | 373 | 'post_type' => 'lesson', |
| 374 | 374 | 'post_status' => 'publish', |
@@ -378,18 +378,18 @@ discard block |
||
| 378 | 378 | 'order' => $args['order'], |
| 379 | 379 | ); |
| 380 | 380 | |
| 381 | - if( $this->course_id ) { |
|
| 381 | + if ($this->course_id) { |
|
| 382 | 382 | $lesson_args['meta_query'][] = array( |
| 383 | 383 | 'key' => '_lesson_course', |
| 384 | 384 | 'value' => $this->course_id, |
| 385 | 385 | ); |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - if( $args['search'] ) { |
|
| 388 | + if ($args['search']) { |
|
| 389 | 389 | $lesson_args['s'] = $args['search']; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - $lessons_query = new WP_Query( apply_filters( 'sensei_learners_filter_lessons', $lesson_args ) ); |
|
| 392 | + $lessons_query = new WP_Query(apply_filters('sensei_learners_filter_lessons', $lesson_args)); |
|
| 393 | 393 | |
| 394 | 394 | $this->total_items = $lessons_query->found_posts; |
| 395 | 395 | return $lessons_query->posts; |
@@ -400,22 +400,22 @@ discard block |
||
| 400 | 400 | * @since 1.7.0 |
| 401 | 401 | * @return array learners |
| 402 | 402 | */ |
| 403 | - private function get_learners( $args ) { |
|
| 403 | + private function get_learners($args) { |
|
| 404 | 404 | |
| 405 | 405 | $user_ids = false; |
| 406 | 406 | $post_id = 0; |
| 407 | 407 | $activity = ''; |
| 408 | 408 | |
| 409 | - if( $this->lesson_id ) { |
|
| 410 | - $post_id = intval( $this->lesson_id ); |
|
| 409 | + if ($this->lesson_id) { |
|
| 410 | + $post_id = intval($this->lesson_id); |
|
| 411 | 411 | $activity = 'sensei_lesson_status'; |
| 412 | 412 | } |
| 413 | - elseif( $this->course_id ) { |
|
| 414 | - $post_id = intval( $this->course_id ); |
|
| 413 | + elseif ($this->course_id) { |
|
| 414 | + $post_id = intval($this->course_id); |
|
| 415 | 415 | $activity = 'sensei_course_status'; |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - if( ! $post_id || ! $activity ) { |
|
| 418 | + if ( ! $post_id || ! $activity) { |
|
| 419 | 419 | $this->total_items = 0; |
| 420 | 420 | return array(); |
| 421 | 421 | } |
@@ -431,32 +431,32 @@ discard block |
||
| 431 | 431 | ); |
| 432 | 432 | |
| 433 | 433 | // Searching users on statuses requires sub-selecting the statuses by user_ids |
| 434 | - if ( $args['search'] ) { |
|
| 434 | + if ($args['search']) { |
|
| 435 | 435 | $user_args = array( |
| 436 | - 'search' => '*' . $args['search'] . '*', |
|
| 436 | + 'search' => '*'.$args['search'].'*', |
|
| 437 | 437 | 'fields' => 'ID' |
| 438 | 438 | ); |
| 439 | 439 | // Filter for extending |
| 440 | - $user_args = apply_filters( 'sensei_learners_search_users', $user_args ); |
|
| 441 | - if ( !empty( $user_args ) ) { |
|
| 442 | - $learners_search = new WP_User_Query( $user_args ); |
|
| 440 | + $user_args = apply_filters('sensei_learners_search_users', $user_args); |
|
| 441 | + if ( ! empty($user_args)) { |
|
| 442 | + $learners_search = new WP_User_Query($user_args); |
|
| 443 | 443 | $activity_args['user_id'] = $learners_search->get_results(); |
| 444 | 444 | } |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - $activity_args = apply_filters( 'sensei_learners_filter_users', $activity_args ); |
|
| 447 | + $activity_args = apply_filters('sensei_learners_filter_users', $activity_args); |
|
| 448 | 448 | |
| 449 | 449 | // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice |
| 450 | - $total_learners = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); |
|
| 450 | + $total_learners = Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); |
|
| 451 | 451 | // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? |
| 452 | - if ( $total_learners < $activity_args['offset'] ) { |
|
| 453 | - $new_paged = floor( $total_learners / $activity_args['number'] ); |
|
| 452 | + if ($total_learners < $activity_args['offset']) { |
|
| 453 | + $new_paged = floor($total_learners / $activity_args['number']); |
|
| 454 | 454 | $activity_args['offset'] = $new_paged * $activity_args['number']; |
| 455 | 455 | } |
| 456 | - $learners = Sensei_Utils::sensei_check_for_activity( $activity_args, true ); |
|
| 456 | + $learners = Sensei_Utils::sensei_check_for_activity($activity_args, true); |
|
| 457 | 457 | // Need to always return an array, even with only 1 item |
| 458 | - if ( !is_array($learners) ) { |
|
| 459 | - $learners = array( $learners ); |
|
| 458 | + if ( ! is_array($learners)) { |
|
| 459 | + $learners = array($learners); |
|
| 460 | 460 | } |
| 461 | 461 | $this->total_items = $total_learners; |
| 462 | 462 | return $learners; |
@@ -469,22 +469,22 @@ discard block |
||
| 469 | 469 | * @return void |
| 470 | 470 | */ |
| 471 | 471 | public function no_items() { |
| 472 | - switch( $this->view ) { |
|
| 472 | + switch ($this->view) { |
|
| 473 | 473 | case 'learners' : |
| 474 | - $text = __( 'No learners found.', 'woothemes-sensei' ); |
|
| 474 | + $text = __('No learners found.', 'woothemes-sensei'); |
|
| 475 | 475 | break; |
| 476 | 476 | |
| 477 | 477 | case 'lessons' : |
| 478 | - $text = __( 'No lessons found.', 'woothemes-sensei' ); |
|
| 478 | + $text = __('No lessons found.', 'woothemes-sensei'); |
|
| 479 | 479 | break; |
| 480 | 480 | |
| 481 | 481 | case 'courses': |
| 482 | 482 | case 'default': |
| 483 | 483 | default: |
| 484 | - $text = __( 'No courses found.', 'woothemes-sensei' ); |
|
| 484 | + $text = __('No courses found.', 'woothemes-sensei'); |
|
| 485 | 485 | break; |
| 486 | 486 | } |
| 487 | - echo apply_filters( 'sensei_learners_no_items_text', $text ); |
|
| 487 | + echo apply_filters('sensei_learners_no_items_text', $text); |
|
| 488 | 488 | } // End no_items() |
| 489 | 489 | |
| 490 | 490 | /** |
@@ -495,40 +495,40 @@ discard block |
||
| 495 | 495 | public function data_table_header() { |
| 496 | 496 | |
| 497 | 497 | echo '<div class="learners-selects">'; |
| 498 | - do_action( 'sensei_learners_before_dropdown_filters' ); |
|
| 498 | + do_action('sensei_learners_before_dropdown_filters'); |
|
| 499 | 499 | |
| 500 | 500 | // Display Course Categories only on default view |
| 501 | - if( 'courses' == $this->view ) { |
|
| 501 | + if ('courses' == $this->view) { |
|
| 502 | 502 | |
| 503 | 503 | $selected_cat = 0; |
| 504 | - if ( isset( $_GET['course_cat'] ) && '' != esc_html( $_GET['course_cat'] ) ) { |
|
| 505 | - $selected_cat = intval( $_GET['course_cat'] ); |
|
| 504 | + if (isset($_GET['course_cat']) && '' != esc_html($_GET['course_cat'])) { |
|
| 505 | + $selected_cat = intval($_GET['course_cat']); |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | - $cats = get_terms( 'course-category', array( 'hide_empty' => false ) ); |
|
| 508 | + $cats = get_terms('course-category', array('hide_empty' => false)); |
|
| 509 | 509 | |
| 510 | - echo '<div class="select-box">' . "\n"; |
|
| 510 | + echo '<div class="select-box">'."\n"; |
|
| 511 | 511 | |
| 512 | - echo '<select id="course-category-options" data-placeholder="' . __( 'Course Category', 'woothemes-sensei' ) . '" name="learners_course_cat" class="chosen_select widefat">' . "\n"; |
|
| 512 | + echo '<select id="course-category-options" data-placeholder="'.__('Course Category', 'woothemes-sensei').'" name="learners_course_cat" class="chosen_select widefat">'."\n"; |
|
| 513 | 513 | |
| 514 | - echo '<option value="0">' . __( 'All Course Categories', 'woothemes-sensei' ) . '</option>' . "\n"; |
|
| 514 | + echo '<option value="0">'.__('All Course Categories', 'woothemes-sensei').'</option>'."\n"; |
|
| 515 | 515 | |
| 516 | - foreach( $cats as $cat ) { |
|
| 517 | - echo '<option value="' . $cat->term_id . '"' . selected( $cat->term_id, $selected_cat, false ) . '>' . $cat->name . '</option>' . "\n"; |
|
| 516 | + foreach ($cats as $cat) { |
|
| 517 | + echo '<option value="'.$cat->term_id.'"'.selected($cat->term_id, $selected_cat, false).'>'.$cat->name.'</option>'."\n"; |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | - echo '</select>' . "\n"; |
|
| 520 | + echo '</select>'."\n"; |
|
| 521 | 521 | |
| 522 | - echo '</div>' . "\n"; |
|
| 522 | + echo '</div>'."\n"; |
|
| 523 | 523 | } |
| 524 | 524 | echo '</div><!-- /.learners-selects -->'; |
| 525 | 525 | |
| 526 | 526 | $menu = array(); |
| 527 | 527 | // Have Course no Lesson |
| 528 | - if( $this->course_id && ! $this->lesson_id ) { |
|
| 528 | + if ($this->course_id && ! $this->lesson_id) { |
|
| 529 | 529 | |
| 530 | 530 | $learners_class = $lessons_class = ''; |
| 531 | - switch( $this->view ) { |
|
| 531 | + switch ($this->view) { |
|
| 532 | 532 | case 'learners': |
| 533 | 533 | $learners_class = 'current'; |
| 534 | 534 | break; |
@@ -547,12 +547,12 @@ discard block |
||
| 547 | 547 | $learner_args['view'] = 'learners'; |
| 548 | 548 | $lesson_args['view'] = 'lessons'; |
| 549 | 549 | |
| 550 | - $menu['learners'] = '<a class="' . $learners_class . '" href="' . esc_url( add_query_arg( $learner_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Learners', 'woothemes-sensei' ) . '</a>'; |
|
| 551 | - $menu['lessons'] = '<a class="' . $lessons_class . '" href="' . esc_url( add_query_arg( $lesson_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Lessons', 'woothemes-sensei' ) . '</a>'; |
|
| 550 | + $menu['learners'] = '<a class="'.$learners_class.'" href="'.esc_url(add_query_arg($learner_args, admin_url('admin.php'))).'">'.__('Learners', 'woothemes-sensei').'</a>'; |
|
| 551 | + $menu['lessons'] = '<a class="'.$lessons_class.'" href="'.esc_url(add_query_arg($lesson_args, admin_url('admin.php'))).'">'.__('Lessons', 'woothemes-sensei').'</a>'; |
|
| 552 | 552 | |
| 553 | 553 | } |
| 554 | 554 | // Have Course and Lesson |
| 555 | - elseif( $this->course_id && $this->lesson_id ) { |
|
| 555 | + elseif ($this->course_id && $this->lesson_id) { |
|
| 556 | 556 | |
| 557 | 557 | $query_args = array( |
| 558 | 558 | 'page' => $this->page_slug, |
@@ -560,18 +560,18 @@ discard block |
||
| 560 | 560 | 'view' => 'lessons' |
| 561 | 561 | ); |
| 562 | 562 | |
| 563 | - $course = get_the_title( $this->course_id ); |
|
| 563 | + $course = get_the_title($this->course_id); |
|
| 564 | 564 | |
| 565 | - $menu['back'] = '<a href="' . esc_url( add_query_arg( $query_args, admin_url( 'admin.php' ) ) ) . '">' . sprintf( __( '%1$sBack to %2$s%3$s', 'woothemes-sensei' ), '<em>← ', $course, '</em>' ) . '</a>'; |
|
| 565 | + $menu['back'] = '<a href="'.esc_url(add_query_arg($query_args, admin_url('admin.php'))).'">'.sprintf(__('%1$sBack to %2$s%3$s', 'woothemes-sensei'), '<em>← ', $course, '</em>').'</a>'; |
|
| 566 | 566 | } |
| 567 | - $menu = apply_filters( 'sensei_learners_sub_menu', $menu ); |
|
| 568 | - if ( !empty($menu) ) { |
|
| 569 | - echo '<ul class="subsubsub">' . "\n"; |
|
| 570 | - foreach ( $menu as $class => $item ) { |
|
| 571 | - $menu[ $class ] = "\t<li class='$class'>$item"; |
|
| 567 | + $menu = apply_filters('sensei_learners_sub_menu', $menu); |
|
| 568 | + if ( ! empty($menu)) { |
|
| 569 | + echo '<ul class="subsubsub">'."\n"; |
|
| 570 | + foreach ($menu as $class => $item) { |
|
| 571 | + $menu[$class] = "\t<li class='$class'>$item"; |
|
| 572 | 572 | } |
| 573 | - echo implode( " |</li>\n", $menu ) . "</li>\n"; |
|
| 574 | - echo '</ul>' . "\n"; |
|
| 573 | + echo implode(" |</li>\n", $menu)."</li>\n"; |
|
| 574 | + echo '</ul>'."\n"; |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | } // End data_table_header() |
@@ -596,50 +596,50 @@ discard block |
||
| 596 | 596 | $form_post_type = ''; |
| 597 | 597 | $form_course_id = 0; |
| 598 | 598 | $form_lesson_id = 0; |
| 599 | - if( $this->course_id && ! $this->lesson_id ) { |
|
| 600 | - $post_title = get_the_title( $this->course_id ); |
|
| 601 | - $post_type = __( 'Course', 'woothemes-sensei' ); |
|
| 599 | + if ($this->course_id && ! $this->lesson_id) { |
|
| 600 | + $post_title = get_the_title($this->course_id); |
|
| 601 | + $post_type = __('Course', 'woothemes-sensei'); |
|
| 602 | 602 | $form_post_type = 'course'; |
| 603 | 603 | $form_course_id = $this->course_id; |
| 604 | 604 | } |
| 605 | - elseif( $this->course_id && $this->lesson_id ) { |
|
| 606 | - $post_title = get_the_title( $this->lesson_id ); |
|
| 607 | - $post_type = __( 'Lesson', 'woothemes-sensei' ); |
|
| 605 | + elseif ($this->course_id && $this->lesson_id) { |
|
| 606 | + $post_title = get_the_title($this->lesson_id); |
|
| 607 | + $post_type = __('Lesson', 'woothemes-sensei'); |
|
| 608 | 608 | $form_post_type = 'lesson'; |
| 609 | 609 | $form_course_id = $this->course_id; |
| 610 | 610 | $form_lesson_id = $this->lesson_id; |
| 611 | - $course_title = get_the_title( $this->course_id ); |
|
| 611 | + $course_title = get_the_title($this->course_id); |
|
| 612 | 612 | } |
| 613 | - if ( empty($form_post_type) ) { |
|
| 613 | + if (empty($form_post_type)) { |
|
| 614 | 614 | return; |
| 615 | 615 | } |
| 616 | 616 | ?> |
| 617 | 617 | <div class="postbox"> |
| 618 | - <h3><span><?php printf( __( 'Add Learner to %1$s', 'woothemes-sensei' ), $post_type ); ?></span></h3> |
|
| 618 | + <h3><span><?php printf(__('Add Learner to %1$s', 'woothemes-sensei'), $post_type); ?></span></h3> |
|
| 619 | 619 | <div class="inside"> |
| 620 | 620 | <form name="add_learner" action="" method="post"> |
| 621 | 621 | <p> |
| 622 | - <input name="add_user_id" placeholder="<?php _e( 'Find learner', 'woothemes-sensei' ) ;?>" id="add_learner_search" style="min-width:300px;" /> |
|
| 623 | - <?php if( 'lesson' == $form_post_type ) { ?> |
|
| 624 | - <label for="add_complete_lesson"><input type="checkbox" id="add_complete_lesson" name="add_complete_lesson" value="yes" /> <?php _e( 'Complete lesson for learner', 'woothemes-sensei' ); ?></label> |
|
| 625 | - <?php } elseif( 'course' == $form_post_type ) { ?> |
|
| 626 | - <label for="add_complete_course"><input type="checkbox" id="add_complete_course" name="add_complete_course" value="yes" /> <?php _e( 'Complete course for learner', 'woothemes-sensei' ); ?></label> |
|
| 622 | + <input name="add_user_id" placeholder="<?php _e('Find learner', 'woothemes-sensei'); ?>" id="add_learner_search" style="min-width:300px;" /> |
|
| 623 | + <?php if ('lesson' == $form_post_type) { ?> |
|
| 624 | + <label for="add_complete_lesson"><input type="checkbox" id="add_complete_lesson" name="add_complete_lesson" value="yes" /> <?php _e('Complete lesson for learner', 'woothemes-sensei'); ?></label> |
|
| 625 | + <?php } elseif ('course' == $form_post_type) { ?> |
|
| 626 | + <label for="add_complete_course"><input type="checkbox" id="add_complete_course" name="add_complete_course" value="yes" /> <?php _e('Complete course for learner', 'woothemes-sensei'); ?></label> |
|
| 627 | 627 | <?php } ?> |
| 628 | 628 | <br/> |
| 629 | - <span class="description"><?php _e( 'Search for a user by typing their name or username.', 'woothemes-sensei' ); ?></span> |
|
| 629 | + <span class="description"><?php _e('Search for a user by typing their name or username.', 'woothemes-sensei'); ?></span> |
|
| 630 | 630 | </p> |
| 631 | - <p><?php submit_button( sprintf( __( 'Add to \'%1$s\'', 'woothemes-sensei' ), $post_title ), 'primary', 'add_learner_submit', false, array() ); ?></p> |
|
| 632 | - <?php if( 'lesson' == $form_post_type ) { ?> |
|
| 633 | - <p><span class="description"><?php printf( __( 'Learner will also be added to the course \'%1$s\' if they are not already taking it.', 'woothemes-sensei' ), $course_title ); ?></span></p> |
|
| 631 | + <p><?php submit_button(sprintf(__('Add to \'%1$s\'', 'woothemes-sensei'), $post_title), 'primary', 'add_learner_submit', false, array()); ?></p> |
|
| 632 | + <?php if ('lesson' == $form_post_type) { ?> |
|
| 633 | + <p><span class="description"><?php printf(__('Learner will also be added to the course \'%1$s\' if they are not already taking it.', 'woothemes-sensei'), $course_title); ?></span></p> |
|
| 634 | 634 | <?php } ?> |
| 635 | 635 | |
| 636 | 636 | <input type="hidden" name="add_post_type" value="<?php echo $form_post_type; ?>" /> |
| 637 | 637 | <input type="hidden" name="add_course_id" value="<?php echo $form_course_id; ?>" /> |
| 638 | 638 | <input type="hidden" name="add_lesson_id" value="<?php echo $form_lesson_id; ?>" /> |
| 639 | 639 | <?php |
| 640 | - do_action( 'sensei_learners_add_learner_form' ); |
|
| 640 | + do_action('sensei_learners_add_learner_form'); |
|
| 641 | 641 | ?> |
| 642 | - <?php wp_nonce_field( 'add_learner_to_sensei', 'add_learner_nonce' ); ?> |
|
| 642 | + <?php wp_nonce_field('add_learner_to_sensei', 'add_learner_nonce'); ?> |
|
| 643 | 643 | </form> |
| 644 | 644 | </div> |
| 645 | 645 | </div> |
@@ -651,19 +651,19 @@ discard block |
||
| 651 | 651 | * @since 1.7.0 |
| 652 | 652 | * @return void |
| 653 | 653 | */ |
| 654 | - public function search_button( $text = '' ) { |
|
| 654 | + public function search_button($text = '') { |
|
| 655 | 655 | |
| 656 | - switch( $this->view ) { |
|
| 656 | + switch ($this->view) { |
|
| 657 | 657 | case 'learners': |
| 658 | - $text = __( 'Search Learners', 'woothemes-sensei' ); |
|
| 658 | + $text = __('Search Learners', 'woothemes-sensei'); |
|
| 659 | 659 | break; |
| 660 | 660 | |
| 661 | 661 | case 'lessons': |
| 662 | - $text = __( 'Search Lessons', 'woothemes-sensei' ); |
|
| 662 | + $text = __('Search Lessons', 'woothemes-sensei'); |
|
| 663 | 663 | break; |
| 664 | 664 | |
| 665 | 665 | default: |
| 666 | - $text = __( 'Search Courses', 'woothemes-sensei' ); |
|
| 666 | + $text = __('Search Courses', 'woothemes-sensei'); |
|
| 667 | 667 | break; |
| 668 | 668 | } |
| 669 | 669 | |