Changeset 2661450
- Timestamp:
- 01/21/2022 03:46:37 PM (4 years ago)
- Location:
- reset-course-progress-for-learndash
- Files:
-
- 14 added
- 4 deleted
- 9 edited
-
assets/screenshot-1.PNG (deleted)
-
assets/screenshot-1.gif (deleted)
-
assets/screenshot-1.png (added)
-
assets/screenshot-10.png (added)
-
assets/screenshot-11.png (added)
-
assets/screenshot-12.png (added)
-
assets/screenshot-2.PNG (deleted)
-
assets/screenshot-2.png (added)
-
assets/screenshot-3.PNG (deleted)
-
assets/screenshot-3.png (added)
-
assets/screenshot-4.png (added)
-
assets/screenshot-5.png (added)
-
assets/screenshot-6.png (added)
-
assets/screenshot-7.png (added)
-
assets/screenshot-8.png (added)
-
assets/screenshot-9.png (added)
-
trunk/assets/css/backend.css (modified) (9 diffs)
-
trunk/assets/js/backend-select2-addition.js (added)
-
trunk/assets/js/backend.js (modified) (15 diffs)
-
trunk/includes/admin/class-rcpl-admin.php (modified) (7 diffs)
-
trunk/includes/admin/class-rcpl-result.php (added)
-
trunk/includes/class-rcpl-functions.php (modified) (13 diffs)
-
trunk/includes/class-reset-by-group.php (modified) (6 diffs)
-
trunk/includes/class-reset-by-role.php (modified) (6 diffs)
-
trunk/includes/class-reset-by-users.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/reset-course-progress-for-learndash.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
reset-course-progress-for-learndash/trunk/assets/css/backend.css
r2619924 r2661450 2 2 visibility: hidden; 3 3 position: relative; 4 height: 272px;5 max-height: 272px;6 4 padding: 10px 20px; 7 5 } … … 14 12 } 15 13 span.select2-container { 16 width: 5 0% !important;14 width: 55% !important; 17 15 position: absolute; 18 16 left: 12%; 17 /*top: 8px;*/ 19 18 } 20 19 .nav-tab-wrapper { … … 35 34 .rcpl-form-wrap { 36 35 clear: both; 37 /*padding-left: 20px;*/38 36 position: relative; 39 37 } … … 46 44 min-width: 255px; 47 45 border: 1px solid #c3c4c7; 48 box-shadow: 0 1px 1px rgb(0 0 0 / 4%);46 box-shadow: 0 1px 1px rgb(0 0 0); 49 47 background: #fff; 50 48 } 51 49 .rcpl-wrap .rcpl-wrapper { 52 padding: 26px 0; 50 padding: 15px 0; 51 margin-bottom: 20px; 53 52 position: relative; 54 53 } … … 71 70 line-height: 1.4; 72 71 border-bottom: 1px solid #c3c4c7; 73 }74 .ajax-course-data-fetching {75 position: absolute;76 left: 36%;77 font-weight: 600;78 z-index: 999999;79 letter-spacing: 2px;80 color: #008000;81 transform: translate( -50%, -50% );82 display: none;83 72 } 84 73 .select2-selection--single { … … 124 113 position: absolute; 125 114 left: 12%; 126 top: 1 05%;115 top: 120%; 127 116 display: block; 128 117 color: #e13c3c; … … 153 142 width: 28px; 154 143 } 155 .rcpl-success-message span{156 color: # 999999;144 .rcpl-success-message .rcpl-loading-wrap { 145 color: #008000; 157 146 font-size: 20px; 158 147 vertical-align: super; 159 148 position: relative; 160 149 margin-left: 5px; 150 display: inline; 161 151 } 162 152 .rcpl-wrapper .rcpl-left { … … 236 226 } 237 227 } 238 /*** end enimated dot ***/ 228 /*** end enimated dot ***/ 239 229 240 230 /* Tabs desing css */ … … 311 301 max-width: 200px !important; 312 302 } 303 .rcpl-user-role-hidden-items { 304 display: none; 305 } 306 .rcpl-reset-note { 307 font-weight: 600; 308 color: #e34949; 309 margin-top: 50px; 310 } 311 .jconfirm-holder { 312 padding-top: 40px; 313 padding-bottom: 40px; 314 position: absolute; 315 left: 50%; 316 top: 50%; 317 transform: translate(-50%, -50%); 318 } 319 .jconfirm .jconfirm-box div.jconfirm-content-pane .jconfirm-content { 320 overflow: unset !important; 321 } 322 .rcpl-disabled { 323 pointer-events: none; 324 opacity: 0.4; 325 } 326 .rcpl-data-table { 327 padding: 0 30px 0 15px; 328 } -
reset-course-progress-for-learndash/trunk/assets/js/backend.js
r2619924 r2661450 4 4 init: function() { 5 5 this.addLoaderOnPageLoad(); 6 this.addExternalSelectBox();7 6 this.onChangeOnGroup(); 8 7 this.onChangeOnRuleOptions(); 9 8 this.resetCourseByUsers(); 10 9 this.resetCourseByUserRoles(); 10 this.onChangeUsersField(); 11 11 this.resetCourseByGroup(); 12 12 }, 13 13 14 14 /** 15 * Exicute js functionality after page load 15 * Save user IDs on change users field 16 */ 17 onChangeUsersField: function() { 18 19 if( $( '.rcpl-select-user-list' ).length > 0 ) { 20 21 $( '.rcpl-select-user-list' ).on( 'change', function() { 22 23 let self = $( this ); 24 let userIDs = self.val(); 25 26 let parent = self.parents( '.rcpl-form-wrap' ); 27 28 $( '.rcpl-save-user-ids' ).val( userIDs ); 29 30 31 32 } ); 33 } 34 }, 35 36 /** 37 * Execute js functionality after page load 16 38 */ 17 39 addLoaderOnPageLoad: function() { 18 40 19 window.onload = function(){ 20 41 $( document ).ready( function() { 21 42 $( '.rcpl-form-content' ).css( 'visibility', 'visible' ); 22 43 $( '.rcpl-page-loader' ).hide(); 23 } 44 }); 24 45 }, 25 46 … … 40 61 let parent = self.parents( '.rcpl-form-wrap' ); 41 62 42 let groupID = parent.find( '.rcpl- group-list' ).val();43 if( RCPLbackEnd.formValidation( groupID, parent, '.rcpl- group-list' ) ) {44 45 error++; 46 } 47 63 let groupID = parent.find( '.rcpl-save-group-ids' ).val(); 64 if( RCPLbackEnd.formValidation( groupID, parent, '.rcpl-select-group-list' ) ) { 65 66 error++; 67 } 68 48 69 let resetRule = parent.find( '.rcpl-select-rules-option:checked' ).val(); 49 70 if( RCPLbackEnd.formValidation( resetRule, parent, '.rcpl-select-rules-option' ) ) { 50 71 51 72 error++; 52 73 } … … 57 78 coursesIDs = parent.find( '.rcpl-select-course-list' ).val(); 58 79 if( RCPLbackEnd.formValidation( coursesIDs, parent, '.rcpl-select-course-list' ) ) { 59 80 60 81 error++; 61 82 } 62 83 } 84 85 let lessonIDs = ''; 86 let topicIDs = ''; 87 let quizID = ''; 88 let lessonReset = false; 89 let topicReset = false; 90 let progressOption = ''; 91 92 63 93 64 94 if( error != 0 ) 65 95 return false; 66 96 67 RCPLbackEnd.ex icuteAjaxAfterErrorRemove( 'rcpl_reset_course_by_group', groupID, resetRule, coursesIDs);68 } ); 69 } 70 }, 97 RCPLbackEnd.executeAjaxAfterErrorRemove( 'rcpl_reset_course_by_group', groupID, resetRule, coursesIDs, progressOption, lessonIDs, topicIDs, quizID, lessonReset, topicReset ); 98 } ); 99 } 100 }, 71 101 72 102 /** … … 79 109 $( '.rcpl-reset-by-roles' ).on( 'click', function() { 80 110 81 console.log( $( '.rcpl-validate-msg' ).html( '' ));111 $( '.rcpl-validate-msg' ).html( '' ); 82 112 83 113 let error = 0; … … 91 121 error++; 92 122 } 93 123 94 124 let resetRule = parent.find( '.rcpl-select-rules-option:checked' ).val(); 95 125 if( RCPLbackEnd.formValidation( resetRule, parent, '.rcpl-select-rules-option' ) ) { 96 126 97 127 error++; 98 128 } … … 103 133 coursesIDs = parent.find( '.rcpl-select-course-list' ).val(); 104 134 if( RCPLbackEnd.formValidation( coursesIDs, parent, '.rcpl-select-course-list' ) ) { 105 135 106 136 error++; 107 137 } 108 138 } 139 140 let lessonIDs = ''; 141 let topicIDs = ''; 142 let quizID = ''; 143 let progressOption = ''; 144 let lessonReset = false; 145 let topicReset = false; 146 147 /* </fs_premium_only> */ 148 progressOption = parent.find( '.rcpl-reset-progress-option:checked' ).val(); 149 if( 'reset_quiz_progress' == progressOption ) { 150 151 lessonIDs = parent.find( '.rcpl-select-lesson-list' ).val(); 152 if( lessonIDs != '' ) { 153 154 topicIDs = parent.find( '.rcpl-select-topic-list' ).val(); 155 } 156 157 quizID = parent.find( '.rcpl-select-quiz-list' ).val(); 158 if( $( '.rcpl-reset-lessons' ).prop( 'checked' ) == true ) { 159 160 lessonReset = true; 161 } 162 163 if( $( '.rcpl-reset-topics' ).prop( 'checked' ) == true ) { 164 165 topicReset = true; 166 } 167 } 168 /* </fs_premium_only> */ 109 169 110 170 if( error != 0 ) 111 171 return false; 112 113 RCPLbackEnd.exicuteAjaxAfterErrorRemove( 'rcpl_reset_course_by_roles', userRoles, resetRule, coursesIDs ); 114 172 RCPLbackEnd.executeAjaxAfterErrorRemove( 'rcpl_reset_course_by_roles', userRoles, resetRule, coursesIDs, progressOption, lessonIDs, topicIDs, quizID, lessonReset, topicReset ); 115 173 } ); 116 174 } … … 133 191 let parent = self.parents( '.rcpl-form-wrap' ); 134 192 135 let userIDs = parent.find( '.rcpl-select-user-list' ).val(); 193 194 195 let userIDs = $( '.rcpl-save-user-ids' ).val(); 136 196 if( RCPLbackEnd.formValidation( userIDs, parent, '.rcpl-select-user-list' ) ) { 137 197 138 198 error++; 139 199 } 140 200 141 201 let resetRule = parent.find( '.rcpl-select-rules-option:checked' ).val(); 142 202 if( RCPLbackEnd.formValidation( resetRule, parent, '.rcpl-select-rules-option' ) ) { 143 203 144 204 error++; 145 205 } … … 150 210 coursesIDs = parent.find( '.rcpl-select-course-list' ).val(); 151 211 if( RCPLbackEnd.formValidation( coursesIDs, parent, '.rcpl-select-course-list' ) ) { 152 212 153 213 error++; 154 214 } 155 215 } 216 217 let progressOption = ''; 218 let lessonIDs = ''; 219 let topicIDs = ''; 220 let quizID = ''; 221 let lessonReset = false; 222 let topicReset = false; 223 224 156 225 157 226 if( error != 0 ) { … … 159 228 } 160 229 161 RCPLbackEnd.ex icuteAjaxAfterErrorRemove( 'rcpl_reset_course_by_users', userIDs, resetRule, coursesIDs);230 RCPLbackEnd.executeAjaxAfterErrorRemove( 'rcpl_reset_course_by_users', userIDs, resetRule, coursesIDs, progressOption, lessonIDs, topicIDs, quizID, lessonReset, topicReset ); 162 231 163 232 } ); … … 167 236 /** 168 237 * Exicute Ajax functionality after error message. 169 * 238 * 170 239 * @param action 171 240 * @param targetID 172 241 * @param resetRule 173 242 * @param courseIDs 174 */ 175 exicuteAjaxAfterErrorRemove: function( action, targetID, resetRule, courseIDs ) { 243 * @param progressOption ( is_premium ) 244 * @param lessonIDs ( is_premium ) 245 * @param topicIDs ( is_premium ) 246 * @param quizIds ( is_mremium ) 247 */ 248 executeAjaxAfterErrorRemove: function(action, targetID, resetRule, courseIDs, progressOption, lessonIDs, topicIDs, quizIds, lessonReset, topicReset ) { 249 250 // let resetMessage = $( '.rcpl-note' ).text(); 251 let resetMessage = 'Do you really want to reset the course/courses?'; 176 252 177 253 setTimeout( function() { 178 254 179 if( confirm( 'Are you sure to reset courses for the selected criteria?' ) ) { 180 181 RCPLbackEnd.successResponseAlert( 'before' ); 182 183 let data = { 184 'action' : action, 185 'target_id' : targetID, 186 'course_ids' : courseIDs, 187 'reset_rule' : resetRule 188 }; 189 190 jQuery.post( ajaxurl, data, function( response ) { 191 192 RCPLbackEnd.successResponseAlert( response ); 193 } ); 194 } 255 $.confirm({ 256 title: false, 257 content: resetMessage, 258 buttons: { 259 Yes: function () { 260 261 RCPLbackEnd.successResponseAlert( 'before' ); 262 263 let ajaxNonce = RcplNonce.security; 264 265 let data = { 266 'action' : action, 267 'security' : ajaxNonce, 268 'target_id' : targetID, 269 'course_ids' : courseIDs, 270 'reset_rule' : resetRule, 271 'progress_option' : progressOption, 272 'lesson_ids' : lessonIDs, 273 'topic_ids' : topicIDs, 274 'quiz_id' : quizIds, 275 'topic_reset' : topicReset 276 }; 277 278 jQuery.post( ajaxurl, data, function( response ) { 279 280 RCPLbackEnd.successResponseAlert( response ); 281 } ); 282 }, 283 No: function () {}, 284 } 285 }); 195 286 196 287 },50 ); … … 199 290 /** 200 291 * Create Validation message 201 * 292 * 202 293 * @param existsVal 203 294 * @param parent … … 206 297 formValidation: function( existsVal, parent, beforeClass ) { 207 298 208 if( '' == existsVal ) {299 if( '' == existsVal || ! existsVal ) { 209 300 parent.find( beforeClass ).parents( '.rcpl-wrapper' ).find( '.rcpl-validate-msg' ).html( 'Please fill out this field.' ); 210 301 211 302 return true; 212 } 303 } 213 304 }, 214 305 215 306 /** 216 307 * Alert message before/after ajax response 217 * 308 * 218 309 * @param response 219 310 */ … … 230 321 console.log( jsonEncode.message ); 231 322 } else { 232 $( '.rcpl-success-message' ).hide(); 233 $( '.rcpl-success-done' ).show(); 234 235 setTimeout( function() { 236 location.reload( true ); 237 }, 1000 ); 323 location.reload( true ); 238 324 } 239 325 } … … 242 328 /** 243 329 * Hide/show courses select field 330 * Save course ids in hidden field 244 331 */ 245 332 onChangeOnRuleOptions: function() { … … 249 336 $( '.rcpl-select-rules-option' ).on( 'change', function() { 250 337 251 switch ( $( this ).val() ) { 252 253 case 'select_courses': 254 $( '.rcpl-select-course-fields' ).show(); 255 256 break; 257 258 case 'all_courses': 259 $( '.rcpl-select-course-fields' ).hide(); 260 $( '.rcpl-select-course-fields' ).find( '#select_course' ).removeAttr( 'required' ); 261 $( '.rcpl-form-content' ).css( 'height', 'unset' ); 262 break; 263 } 264 } ); 265 } 266 }, 267 268 /** 269 * Fetch group course list 338 let self = $( this ); 339 let parent = self.parents( '.rcpl-form-wrap' ); 340 let userOption = $( '.rcpl-selected-users-option:checked' ).val(); 341 if( ! userOption ) { 342 userOption = $( '.rcpl-selected-group-option:checked' ).val(); 343 } 344 345 let progressOption = ''; 346 progressOption = parent.find( '.rcpl-reset-progress-option:checked' ).val(); 347 if( ! progressOption ) { 348 progressOption = 'reset_course_progress'; 349 } 350 351 let userRole = parent.find( '.rcpl-select-user-roles' ).val(); 352 let targetSel = 'user/users'; 353 if( userRole ) { 354 targetSel = 'user role/roles'; 355 } else if( $(".rcpl-select-group-list")[0] ) { 356 targetSel = 'group/groups'; 357 } 358 359 if( 'select_courses' == self.val() ) { 360 361 // Update reset progress text 362 if( 'selected_users' == userOption && 'reset_quiz_progress' == progressOption ) { 363 $( '.rcpl-note' ).html( 'Quizzes will be reset with selected '+targetSel+' and selected courses.' ); 364 } else if( 'all_users' == userOption && 'reset_quiz_progress' == progressOption ) { 365 $( '.rcpl-note' ).html( 'Quizzes will be reset with all '+targetSel+' and selected courses.' ); 366 } else if( 'selected_users' == userOption && 'reset_course_progress' == progressOption ) { 367 $( '.rcpl-note' ).html( 'Selected course/courses will be reset with selected '+targetSel+'.' ); 368 } else if( 'all_users' == userOption && 'reset_course_progress' == progressOption ) { 369 $( '.rcpl-note' ).html( 'Selected course/courses will be reset with all '+targetSel+'.' ); 370 } else { 371 $( '.rcpl-note' ).html( 'Selected course/courses will be reset with selected '+targetSel+'.' ); 372 } 373 // End update reset progress text 374 375 $( '.rcpl-select-course-fields' ).show(); 376 377 } else if( 'all_courses' == self.val() ) { 378 379 // Update reset progress text 380 if( 'selected_users' == userOption && 'reset_quiz_progress' == progressOption ) { 381 $( '.rcpl-note' ).html( 'Quizzes will be reset with selected '+targetSel+' and all courses.' ); 382 } else if( 'all_users' == userOption && 'reset_quiz_progress' == progressOption ) { 383 $( '.rcpl-note' ).html( 'Quizzes will be reset with all '+targetSel+' and all courses.' ); 384 } else if( 'selected_users' == userOption && 'reset_course_progress' == progressOption ) { 385 $( '.rcpl-note' ).html( 'All the courses will be reset with selected '+targetSel+'.' ); 386 } else if( 'all_users' == userOption && 'reset_course_progress' == progressOption ) { 387 $( '.rcpl-note' ).html( 'All the courses will be reset with all '+targetSel+'.' ); 388 } else { 389 $( '.rcpl-note' ).html( 'All the courses will be reset with selected '+targetSel+'.' ); 390 } 391 // End update reset progress text 392 393 $( '.rcpl-select-course-fields' ).hide(); 394 $( '.rcpl-select-course-fields' ).find( '#select_course' ).removeAttr( 'required' ); 395 $( '.rcpl-form-content' ).css( 'height', 'unset' ); 396 } 397 } ); 398 } 399 }, 400 401 /** 402 * Save group id on change select group option 270 403 */ 271 404 onChangeOnGroup: function() { 272 405 273 if( $( '.rcpl-group-list' ).length > 0 ) { 274 $( '.rcpl-group-list' ).on( 'change', function() { 275 276 var self = $(this); 277 var groupID = self.val(); 278 279 $( '.rcpl-select-course-list' ).html( '' ); 280 281 if( self.val() == '' ) { 282 return false; 283 } 284 285 $( '.ajax-course-data-fetching' ).show(); 286 287 var data = { 288 'action' : 'rcpl_get_group_courses', 289 'group_id' : groupID, 290 }; 291 292 jQuery.post( ajaxurl, data, function( response ) { 293 var response = JSON.parse( response ); 294 if( response.status == 'false' ) { 295 console.log( response.message ); 296 } else { 297 $( '.rcpl-select-course-list' ).html( response.content ); 298 $( '.ajax-course-data-fetching' ).hide(); 299 } 300 } ); 301 } ); 302 } 303 }, 304 305 /** 306 * Add select2 Features 307 */ 308 addExternalSelectBox: function() { 309 310 $( '.rcpl-wrapper select' ).select2(); 311 312 $( '.rcpl-wrapper #select_users' ).select2({ 313 placeholder: 'Select Users', 314 allowClear: true 315 }); 316 317 $( '.rcpl-wrapper #select_course' ).select2({ 318 placeholder: 'Select Courses', 319 allowClear: true 320 }); 321 322 $( '.rcpl-wrapper #select_role' ).select2({ 323 placeholder: 'Select User Roles', 324 allowClear: true 325 }); 326 $( '.rcpl-wrapper #select_group' ).select2({ 327 placeholder: 'Select Group', 328 allowClear: true 329 }); 406 if( $( '.rcpl-select-group-list' ).length > 0 ) { 407 $( '.rcpl-select-group-list' ).on( 'change', function() { 408 409 let self = $( this ); 410 let groupID = self.val(); 411 412 let parent = self.parents( '.rcpl-form-wrap' ); 413 414 let groupSelectOption = parent.find( '.rcpl-selected-group-option:checked' ).val(); 415 if( 'selected_users' == groupSelectOption ) { 416 $( '.rcpl-save-group-ids' ).val( groupID ); 417 } else if( 'all_users' == groupSelectOption ) { 418 $( '.rcpl-save-group-ids' ).val( '' ); 419 } else { 420 $( '.rcpl-save-group-ids' ).val( groupID ); 421 } 422 } ); 423 } 330 424 }, 331 425 }; -
reset-course-progress-for-learndash/trunk/includes/admin/class-rcpl-admin.php
r2619924 r2661450 13 13 class RCPL_Admin { 14 14 15 const VERSION = '1.2';16 17 15 /** 18 16 * @var self … … 31 29 self::$instance->hooks(); 32 30 } 33 31 34 32 return self::$instance; 35 33 } … … 44 42 add_filter( 'plugin_action_links_'. RCPL_BASE_DIR, [ $this, 'rcpl_plugin_setting_links' ] ); 45 43 add_action( 'in_admin_header', [ $this, 'rcpl_remove_admin_notices' ], 100 ); 44 45 /** 46 * Live ajax search hooks 47 */ 48 add_action( 'wp_ajax_rcpl_search_users', [ $this, 'rcpl_live_search_users' ] ); 49 add_action( 'wp_ajax_rcpl_search_courses', [ $this, 'rcpl_live_search_course' ] ); 50 add_action( 'wp_ajax_rcpl_search_groups', [ $this, 'rcpl_live_search_groups' ] ); 51 } 52 53 /** 54 * Live search learndash groups 55 */ 56 public function rcpl_live_search_groups() { 57 58 $return = []; 59 $search_query = isset( $_GET['q'] ) ? $_GET['q'] : ''; 60 $user_id = isset( $_GET['user_id'] ) ? ( int ) $_GET['user_id'] : 0; 61 62 $arg = array( 63 's' => $search_query, 64 'post_status' => 'publish', 65 'post_type' => 'groups', 66 'fields' => 'ids', 67 ); 68 69 if( $user_id && 0 != $user_id ) { 70 71 $group_ids = learndash_get_administrators_group_ids( $user_id ); 72 $arg['post__in'] = $group_ids; 73 } 74 75 $search_results = new WP_Query( $arg ); 76 77 if( $search_results->have_posts() ) { 78 79 while( $search_results->have_posts() ) { 80 81 $search_results->the_post(); 82 83 $ids = get_the_id(); 84 $title = get_the_title(); 85 86 $return[] = [ $ids, $title ]; 87 } 88 } 89 90 echo json_encode( $return ); 91 wp_die(); 92 } 93 94 /** 95 * Live search course list using :Ajax 96 */ 97 public function rcpl_live_search_course() { 98 99 $return = []; 100 101 $group_ids = isset( $_GET['group_ids'] ) ? rest_sanitize_array( $_GET['group_ids'] ) : []; 102 $search_query = isset( $_GET['q'] ) ? $_GET['q'] : ''; 103 104 $query_args = [ 105 's' => $search_query, 106 'post_status' => 'publish', 107 'post_type' => learndash_get_post_type_slug( 'course' ), 108 'posts_per_page' => -1, 109 'fields' => 'ids' 110 ]; 111 112 if( ! empty( $group_ids ) ) { 113 114 $loop_count = 1; 115 foreach( $group_ids as $group_id ) { 116 117 $query_args['meta_query'][$group_id] = [ 118 119 'key' => 'learndash_group_enrolled_' . $group_id, 120 'compare' => 'EXISTS' 121 ]; 122 123 $loop_count++; 124 } 125 126 if( $loop_count > 1 ) { 127 $query_args['meta_query']['relation'] = 'OR'; 128 } 129 } 130 131 $search_results = new WP_Query( $query_args ); 132 if( $search_results->have_posts() ) { 133 134 while( $search_results->have_posts() ) { 135 136 $search_results->the_post(); 137 138 $ids = get_the_id(); 139 $title = get_the_title(); 140 141 $return[] = [ $ids, $title ]; 142 } 143 } 144 145 echo json_encode( $return ); 146 wp_die(); 147 } 148 149 /** 150 * Live search users list using :Ajax 151 */ 152 public function rcpl_live_search_users() { 153 154 global $wpdb; 155 156 $return = []; 157 $search_query = isset( $_GET['q'] ) ? $_GET['q'] : ''; 158 $capabilities = $wpdb->prefix.'capabilities'; 159 $get_users = $wpdb->get_results( "SELECT users.ID, users.display_name 160 FROM {$wpdb->users} as users INNER JOIN {$wpdb->usermeta} as usermeta 161 ON users.ID = usermeta.user_id 162 WHERE usermeta.meta_key = '$capabilities' 163 AND usermeta.meta_value NOT LIKE '%administrator%' 164 AND users.user_login LIKE '%{$search_query}%' LIMIT 5", ARRAY_N ); 165 166 if( $get_users ) { 167 $return = $get_users; 168 } 169 170 echo json_encode( $return ); 171 wp_die(); 46 172 } 47 173 … … 103 229 'reset_by_users' => __( 'Reset by Users', 'reset-course-progress-for-learndash' ), 104 230 'reset_by_user_roles' => __( 'Reset by User Roles', 'reset-course-progress-for-learndash' ), 105 'reset_by_group' => __( 'Reset by Group', 'reset-course-progress-for-learndash' ) 231 'reset_by_group' => __( 'Reset by Group', 'reset-course-progress-for-learndash' ), 232 'progress_result' => __( 'Progress Result', 'reset-course-progress-for-learndash' ) 106 233 ]; 107 234 108 $html .= '<div id="rcpl-main-wrap">'; 109 $html .= '<div class="rcpl-global-header">'; 110 $html .= '<h1>'.__( 'Reset Course Progress by LDNinjas.', 'reset-course-progress-for-learndash' ).'</h1>'; 111 $html .= '<div class="rcpl-tab-buttons">'; 112 113 foreach( $tabs as $tab => $name ) { 114 115 $class = ( $tab == $current ) ? 'is-primary' : ''; 116 $html .= '<a href="?page=reset-course-progress-for-learndash&tab=' . $tab . '" class="is-button button components-button '.$class.' ">' . $name . '</a>'; 117 } 118 119 $html .= '</div>'; 120 $html .= '</div>'; 121 $html .= '</div>'; 122 123 $allowed_html = [ 124 'div' => array( 125 'class' => [], 126 'id' => [], 127 ), 128 'span' => array( 129 'class' => [], 130 ), 131 'h1' => array( 132 'class' => [], 133 ), 134 'a' => array( 135 'class' => [], 136 'href' => [], 137 ) 138 ]; 139 140 echo wp_kses( $html, $allowed_html ); 235 ob_start(); 236 237 ?> 238 <!-- Tab Headers --> 239 <div id="rcpl-main-wrap"> 240 <div class="rcpl-global-header"> 241 <h1><?php _e( 'Reset Course Progress For LearnDash.', 'reset-course-progress-for-learndash' ); ?></h1> 242 <div class="rcpl-tab-buttons"> 243 <?php 244 foreach( $tabs as $tab => $name ) { 245 246 $class = ( $tab == $current ) ? 'is-primary' : ''; 247 ?> 248 <a href="<?php echo admin_url( '/admin.php?page=reset-course-progress-for-learndash&tab=' . esc_html( $tab ) ); ?>" class="is-button button components-button <?php echo $class; ?> "><?php echo $name; ?></a> 249 <?php 250 } 251 ?> 252 </div> 253 </div> 254 </div> 255 <!-- Tab Headers --> 256 <?php 257 258 $content = ob_get_contents(); 259 ob_get_clean(); 260 return $content; 141 261 } 142 262 … … 147 267 148 268 $tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reset_by_users'; 149 $this->rcpl_setting_page_tabs( $tab);269 echo wp_kses( $this->rcpl_setting_page_tabs( $tab ), RCPL_Functions::allowed_html() ); 150 270 151 271 if ( $tab == 'reset_by_user_roles' ) { … … 164 284 Reset_by_Group::rcpl_group_tabs_html(); 165 285 } 286 } else if( $tab == 'progress_result' ) { 287 288 if( file_exists( RCPL_INCLUDES_DIR .'admin/class-rcpl-result.php' ) ) { 289 290 require_once RCPL_INCLUDES_DIR . 'admin/class-rcpl-result.php'; 291 } 166 292 } 167 293 } … … 177 303 if( $screen ) { 178 304 179 if( $screen->id == 'learndash-lms_page_reset-course-progress-for-learndash' ) { 305 if( $screen->id == 'learndash-lms_page_reset-course-progress-for-learndash' 306 || $screen->id == 'learndash-lms_page_rcpl-schedule-reset' ) { 180 307 181 308 /** 182 309 * enqueue admin css 183 310 */ 184 wp_enqueue_style( 'rcpl-backend-css', RCPL_ASSETS_URL . 'css/backend.css', [], self::VERSION, null );311 wp_enqueue_style( 'rcpl-backend-css', RCPL_ASSETS_URL . 'css/backend.css', [], RCPL_VERSION, null ); 185 312 wp_enqueue_style( 'external-select-min-css', RCPL_ASSETS_URL .'css/select2.min.css' ); 186 313 wp_enqueue_style( 'rcpl-custom-popup-css-link', 'https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css', [], RCPL_VERSION, null ); 314 187 315 /** 188 316 * add slect2 js 189 317 */ 190 wp_enqueue_script( 'external-select2-jquery-js', RCPL_ASSETS_URL. 'js/select2.full.min.js', ['jquery'], self::VERSION, true ); 191 wp_enqueue_script( 'rcpl-backend-js', RCPL_ASSETS_URL . 'js/backend.js', [ 'jquery' , 'external-select2-jquery-js' ], self::VERSION, true ); 318 wp_enqueue_script( 'external-select2-jquery-js', RCPL_ASSETS_URL. 'js/select2.full.min.js', ['jquery'], RCPL_VERSION, true ); 319 wp_enqueue_script( 'rcpl-backend-js', RCPL_ASSETS_URL . 'js/backend.js', [ 'jquery' , 'external-select2-jquery-js' ], RCPL_VERSION, true ); 320 wp_enqueue_script( 'rcpl-select2-addition', RCPL_ASSETS_URL . 'js/backend-select2-addition.js', [ 'jquery' , 'external-select2-jquery-js' ], RCPL_VERSION, true ); 321 wp_enqueue_script('wt-custom-bootstrap-pop-up-js', 'https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js', ['jquery'], RCPL_VERSION, true); 322 323 wp_localize_script( 'rcpl-backend-js', 'RcplNonce', array( 324 'security' => wp_create_nonce( 'rcpl_ajax_nonce' ) 325 ) ); 192 326 } 193 327 } -
reset-course-progress-for-learndash/trunk/includes/class-rcpl-functions.php
r2619924 r2661450 30 30 31 31 /** 32 * Get disabled class 33 * 34 * @param $action 35 */ 36 public static function get_disabled_class( $action ) { 37 38 $reset_in_progress = ''; 39 $event_count = get_option( $action ); 40 if( $event_count && 0 != $event_count ) { 41 $reset_in_progress = 'rcpl-disabled'; 42 } 43 44 return $reset_in_progress; 45 } 46 47 /** 48 * Update cron event count in db 49 * 50 * @param $action 51 */ 52 public static function update_cron_event_total_count( $action ) { 53 54 $sum = 0; 55 $cron = self::get_cron_schedule_data(); 56 if( ! $cron || ! is_array( $cron ) ) { 57 return false; 58 } 59 60 foreach( $cron as $key => $schedule ) { 61 62 $event = isset( $schedule[$action] ) ? $schedule[$action] : ''; 63 if( empty( $event ) ) { 64 continue; 65 } 66 $sum += count( $schedule[$action] ); 67 } 68 69 update_option( $action, $sum ); 70 } 71 72 /** 73 * Get cron schedules data 74 */ 75 public static function get_cron_schedule_data() { 76 77 $cron = get_option( 'cron' ); 78 if( ! $cron ) { 79 return false; 80 } 81 return $cron; 82 } 83 84 /** 85 * Get increament time 86 * 87 * @param $index 88 */ 89 public static function create_single_events( $index, $action, $args ) { 90 91 $time = time(); 92 $increment = $index * 10; 93 $times = $time + $increment; 94 wp_schedule_single_event( $times, $action, [ $args ] ); 95 } 96 97 /** 98 * Reset note message html content 99 * 100 * @param $tab 101 * @param $reset_in_progress 102 */ 103 public static function reset_note_message_html( $tab, $reset_in_progress, $tab_id ) { 104 105 ob_start(); 106 107 $message = __( '<span>Note:<span> <span class="rcpl-note">Selected course/courses will be reset with selected '.$tab_id.'/'.$tab.'.</span>', 'reset-course-progress-for-learndash' ); 108 109 if( 'rcpl-disabled' == $reset_in_progress ) { 110 $link = admin_url( 'admin.php?page=reset-course-progress-for-learndash&tab=progress_result' ); 111 $message = __( '<span>Note:<span> <span class="rcpl-note">Reset is being processed, please check reset result by clicking this <a href="'.$link.'">button.</a></span>', 'reset-course-progress-for-learndash' ); 112 } 113 ?> 114 <div class="rcpl-reset-note"> 115 <?php echo wp_kses( $message, self::allowed_html() ); ?> 116 </div> 117 <?php 118 119 $content = ob_get_contents(); 120 ob_get_clean(); 121 122 return $content; 123 } 124 125 /** 32 126 * Create html for tabs heading 33 127 * … … 76 170 $allowed_html = [ 77 171 'div' => [ 78 'class' => [] 172 'class' => [], 173 'data-user_id' => [], 174 'id' => [], 79 175 ], 80 176 'label' => [ … … 106 202 'src' => [] 107 203 ], 204 'h1' => [ 205 'class' => [], 206 ], 207 'a' => [ 208 'class' => [], 209 'href' => [] 210 ] 108 211 ]; 109 212 … … 114 217 * Fetching group course dropdown html 115 218 */ 116 public function fetching_group_course_html() {219 public static function fetching_group_course_html() { 117 220 118 221 ob_start(); 119 120 222 ?> 121 223 <div class="rcpl-wrapper rcpl-select-course-fields"> 122 224 <label for="user_course"><?php _e( 'Select Course(s) :', 'reset-course-progress-for-learndash' ); ?></label> 123 <select id="select_course" name="g_course_dropdown[]"class="rcpl-select-course-list" multiple="multiple">225 <select id="select_course" class="rcpl-select-course-list" multiple="multiple"> 124 226 <option disabled="disabled"><?php _e( 'Select Course', 'reset-course-progress-for-learndash' ); ?></option> 125 227 </select> 126 228 <div class="rcpl-validate-msg"></div> 127 <div class="ajax-course-data-fetching"><?php _e( 'Fetching...', 'reset-course-progress-for-learndash' ); ?></div>128 229 </div> 129 230 <?php … … 138 239 * Create group dropdown html 139 240 */ 140 public static function get_group_dropdown_html() { 141 142 $groups = self::get_ids_of_all_groups(); 143 ob_start(); 144 145 ?> 146 <div class="rcpl-wrapper"> 241 public static function get_group_dropdown_html( $user_id ) { 242 243 ob_start(); 244 245 ?> 246 <div data-user_id="<?php echo esc_html( $user_id ); ?>" class="rcpl-wrapper rcpl-select-group-field"> 147 247 <label for="group"><?php _e( 'Select Group :', 'reset-course-progress-for-learndash' ); ?></label> 148 <select id="select_groups" name="rcpl_group_id" class="rcpl-group-list"> 149 <option value=""><?php _e( 'Select Group', 'reset-course-progress-for-learndash' ); ?></option> 150 <?php 151 if( $groups ) { 152 foreach( $groups as $group_id ) { 153 ?> 154 <option value="<?php echo intval( $group_id ); ?>"><?php echo esc_html( get_the_title( $group_id ) ); ?></option> 155 <?php 156 } 157 } 158 ?> 159 </select> 248 <select id="select_groups" class="rcpl-select-group-list" multiple="multiple"></select> 160 249 <div class="rcpl-validate-msg"></div> 161 250 </div> … … 178 267 <div class="rcpl-success-message"> 179 268 <img class="rcpl-success-loader" src="<?php echo RCPL_ASSETS_URL .'images/spinner-2x.gif'; ?>" /> 180 < span><?php _e( 'Reseting progress as per selected criteria' ); ?>269 <div class="rcpl-loading-wrap"><?php _e( 'Please wait! Reset is being processed.' ); ?> 181 270 <div class="rcpl-animated-dot"> 182 271 <div class="dot-pulse"></div> 183 272 </div> 184 </span> 185 </div> 186 <div class="rcpl-success-done"> 187 <span class="dashicons dashicons-yes-alt"></span> 188 <span class="rcpl-done-text"><?php _e( 'Done', 'reset-course-progress-for-learndash' ); ?> </span> 273 </div> 189 274 </div> 190 275 <?php … … 201 286 public static function get_users_dropdown_html() { 202 287 203 $users = self::get_object_of_all_users(); 204 205 ob_start(); 206 ?> 207 <div class="rcpl-wrapper"> 288 ob_start(); 289 ?> 290 <div class="rcpl-wrapper rcpl-select-users-fields"> 208 291 <label for="users"><?php _e( 'Select User(s) :', 'reset-course-progress-for-learndash' ); ?></label> 209 <select id="select_users" name="u_users_dropdown[]" class="rcpl-select-user-list" multiple="multiple"> 210 <option disabled="disabled"><?php _e( 'Select Users', 'reset-course-progress-for-learndash' ); ?></option> 211 <?php 212 if( $users ) { 213 foreach( $users as $user ) { 214 215 ?> 216 <option value="<?php echo intval( $user->ID ); ?>"><?php echo sanitize_user( $user->display_name ); ?></option> 217 <?php 218 } 219 } 220 ?> 292 <select id="select_users" class="rcpl-select-user-list" multiple="multiple"> 293 221 294 </select> 222 295 <div class="rcpl-validate-msg"></div> … … 237 310 global $wp_roles; 238 311 ob_start(); 239 240 ?> 241 <div class="rcpl-wrapper ">312 313 ?> 314 <div class="rcpl-wrapper rcpl-user-role-fields"> 242 315 <label for="user_role"><?php _e( 'Select User Role(s) :', 'reset-course-progress-for-learndash' ); ?></label> 243 <select id="select_role" name="user_role_dropdown[]"class="rcpl-select-user-roles" multiple="multiple">316 <select id="select_role" class="rcpl-select-user-roles" multiple="multiple"> 244 317 <option disabled="disabled"><?php _e( 'Select User Role', 'reset-course-progress-for-learndash' ); ?></option> 245 318 <?php … … 274 347 public static function get_course_field_dropdown_html() { 275 348 276 $course_ids = self::get_ids_of_all_courses();277 278 349 ob_start(); 279 350 ?> 280 351 <div class="rcpl-wrapper rcpl-select-course-fields"> 281 352 <label for="user_course"><?php _e( 'Select Course(s) :', 'reset-course-progress-for-learndash' ); ?></label> 282 <select id="select_course" class="rcpl-select-course-list" multiple="multiple"> 283 <option disabled="disabled"><?php _e( 'Select Course', 'reset-course-progress-for-learndash' ); ?></option> 284 <?php 285 if( $course_ids ) { 286 foreach( $course_ids as $course_id ) { 287 ?> 288 <option value="<?php echo intval( $course_id ); ?>" ><?php echo esc_html( get_the_title( $course_id ) ); ?></option> 289 <?php 290 } 291 } 292 ?> 293 </select> 353 <select id="select_course" class="rcpl-select-course-list" multiple="multiple"></select> 294 354 <div class="rcpl-validate-msg"></div> 295 355 </div> … … 316 376 <input checked="checked" type="radio" value="select_courses" class="rcpl-select-rules-option" name="rcpl_select_rules_option"> 317 377 <span><?php _e( 'Selected courses', 'reset-course-progress-for-learndash' ); ?></span> 318 <input type="radio" value="all_courses" class="rcpl-select-rules-option rcpl- left" name="rcpl_select_rules_option">378 <input type="radio" value="all_courses" class="rcpl-select-rules-option rcpl-rule-left" name="rcpl_select_rules_option"> 319 379 <span><?php _e( 'All courses', 'reset-course-progress-for-learndash' ); ?></span> 320 380 </div> … … 351 411 352 412 /** 353 * Get user ids 354 * 355 * @return $user_ids ( object of user_ids ) 356 */ 357 public static function get_object_of_all_users() { 358 359 $user_ids = get_users( 360 [ 361 'fields' => [ 'ID', 'display_name' ], 362 'role__not_in' => 'Administrator' 363 ] 364 ); 365 366 if( $user_ids ) { 367 return $user_ids; 368 } 413 * Get all user Ids 414 * 415 * @param $user_roles 416 */ 417 public static function get_all_user_ids( $user_roles = '' ) { 418 419 $role_args = [ 420 'role__not_in' => 'administrator' 421 ]; 422 423 if( ! empty( $user_roles ) && is_array( $user_roles ) ) { 424 $role_args = [ 425 'role__in' => $user_roles 426 ]; 427 } 428 429 $args = [ 430 'fields' => 'IDs', 431 'number' => -1 432 ]; 433 434 $arguments = array_merge( $args, $role_args ); 435 $user_query = new WP_User_Query( $arguments ); 436 $users = $user_query->get_results(); 437 438 return $users; 369 439 } 370 440 … … 389 459 390 460 /** 391 * Check if user role exists392 *393 * @param $user_id394 */395 public static function has_user_role( $user_id, $user_role ) {396 397 $user_meta = get_userdata( $user_id );398 399 if( $user_meta ) {400 401 if( in_array( $user_role, $user_meta->roles ) ) {402 return true;403 }404 }405 406 return false;407 }408 409 /**410 461 * Reset LD course by schedule 411 462 * … … 422 473 if( $lesson_list ) { 423 474 foreach( $lesson_list as $lessons ) { 424 475 425 476 /** 426 477 * Mark lesson as incomplete -
reset-course-progress-for-learndash/trunk/includes/class-reset-by-group.php
r2619924 r2661450 5 5 * Do not allow directly accessing this file. 6 6 */ 7 8 if( ! defined( 'ABSPATH' ) ) exit; 7 if ( !defined( 'ABSPATH' ) ) { 8 exit; 9 } 9 10 10 11 /** … … 13 14 class Reset_by_Group { 14 15 15 private static $instance = null;16 private static $instance = null ; 16 17 17 18 /** … … 20 21 */ 21 22 public static function instance() { 22 23 if ( is_null( self::$instance ) && ! ( self::$instance instanceof Reset_by_Group ) ) { 24 25 self::$instance = new self; 26 23 24 if ( is_null( self::$instance ) && !self::$instance instanceof Reset_by_Group ) { 25 self::$instance = new self(); 27 26 self::$instance->hooks(); 28 27 } 29 28 30 29 return self::$instance; 31 30 } 32 33 /** 34 * Shortcodehooks31 32 /** 33 * plugin hooks 35 34 */ 36 35 private function hooks() { 37 36 38 add_action( 'wp_ajax_rcpl_get_group_courses', [ $this, 'rcpl_fetch_group_courses' ] );39 37 add_action( 'wp_ajax_rcpl_reset_course_by_group', [ $this, 'rcpl_reset_course_progress_by_group' ] ); 40 } 41 38 add_action( 'rcpl_reset_by_groups', [ $this, 'rcpl_cron_reset_by_groups' ], 10, 1 ); 39 } 40 41 /** 42 * Course reset using cron job 43 * 44 * @param $args 45 */ 46 public function rcpl_cron_reset_by_groups( $args ) { 47 48 $course_ids = $args['course_ids']; 49 $selected_rule = $args['reset_rule']; 50 $user_id = $args['user_id']; 51 foreach ( $course_ids as $course_id ) { 52 RCPL_Functions::rcpl_course_resets( $course_id, $user_id ); 53 } 54 } 55 42 56 /** 43 57 * Reset users course progress by group : Ajax … … 45 59 public function rcpl_reset_course_progress_by_group() { 46 60 61 check_ajax_referer( 'rcpl_ajax_nonce', 'security' ); 47 62 $response = []; 48 49 $group_id = isset( $_POST['target_id'] ) ? ( int ) $_POST['target_id'] : 0; 50 if( ! intval( $group_id ) ) { 51 63 $group_ids = ( isset( $_POST['target_id'] ) ? rest_sanitize_array( $_POST['target_id'] ) : [] ); 64 65 if ( empty($group_ids) ) { 52 66 $response['status'] = 'false'; 53 67 $response['message'] = __( 'Group ID not found.', 'reset-course-progress-for-learndash' ); 54 echo json_encode( $response );68 echo json_encode( $response ) ; 55 69 wp_die(); 56 70 } 57 58 $selected_rule = isset( $_POST['reset_rule'] ) ? sanitize_text_field( $_POST['reset_rule'] ) : ''; 59 if( empty( $selected_rule ) ) { 60 71 72 $group_ids = array_map( 'intval', $group_ids ); 73 $selected_rule = ( isset( $_POST['reset_rule'] ) ? sanitize_text_field( $_POST['reset_rule'] ) : '' ); 74 75 if ( empty($selected_rule) ) { 61 76 $response['status'] = 'false'; 62 77 $response['message'] = __( 'Reset rule not found.', 'reset-course-progress-for-learndash' ); 63 echo json_encode( $response );78 echo json_encode( $response ) ; 64 79 wp_die(); 65 80 } 66 67 if( 'select_courses' == $selected_rule ) { 68 $course_ids = isset( $_POST['course_ids'] ) ? rest_sanitize_array( $_POST['course_ids'] ) : []; 69 70 } elseif( 'all_courses' == $selected_rule ) { 71 72 $course_ids = learndash_get_group_courses_list( $group_id ); 73 } 74 75 $course_ids = array_map( 'intval', $course_ids ); 76 if( empty( $course_ids ) ) { 77 78 $response['status'] = 'false'; 79 $response['message'] = __( 'Course ID not found.', 'reset-course-progress-for-learndash' ); 80 echo json_encode( $response ); 81 wp_die(); 82 } 83 84 $users = RCPL_Functions::get_object_of_all_users(); 85 if( $users ) { 86 87 foreach( $users as $user ) { 88 89 if( ! learndash_is_user_in_group( (int) $user->ID, $group_id ) ) { 90 continue; 81 82 $p_args = []; 83 foreach ( $group_ids as $group_id ) { 84 85 $user_ids = learndash_get_groups_users( $group_id ); 86 if ( !$user_ids ) { 87 continue; 88 } 89 90 foreach ( $user_ids as $key => $user ) { 91 $user_id = (int) $user->data->ID; 92 $course_ids = ''; 93 94 if ( 'select_courses' == $selected_rule ) { 95 $course_ids = ( isset( $_POST['course_ids'] ) ? rest_sanitize_array( $_POST['course_ids'] ) : [] ); 96 } elseif ( 'all_courses' == $selected_rule ) { 97 $course_ids = learndash_get_group_courses_list( $group_id ); 91 98 } 92 93 foreach( $course_ids as $course_id ) { 94 95 RCPL_Functions::rcpl_course_resets( $course_id, (int) $user->ID ); 96 } 99 100 $course_ids = array_map( 'intval', $course_ids ); 101 $f_args = [ 102 'user_id' => $user_id, 103 'reset_rule' => $selected_rule, 104 'course_ids' => $course_ids, 105 ]; 106 $args = array_merge( $f_args, $p_args ); 107 RCPL_Functions::create_single_events( $key, 'rcpl_reset_by_groups', $args ); 108 RCPL_Functions::update_cron_event_total_count( 'rcpl_reset_by_groups' ); 97 109 } 98 110 } 99 100 111 $response['status'] = 'true'; 101 echo json_encode( $response ); 102 wp_die(); 103 } 104 105 /** 106 * Fetching group course data using : AJax 107 */ 108 public function rcpl_fetch_group_courses() { 109 110 $response = []; 111 112 $group_id = isset( $_POST['group_id'] ) ? ( int ) $_POST['group_id'] : 0; 113 if( ! intval( $group_id ) ) { 114 115 $response['status'] = 'false'; 116 $response['message'] = __( 'Group ID not found.', 'reset-course-progress-for-learndash' ); 117 echo json_encode( $response ); 118 wp_die(); 119 } 120 121 $g_course_list = learndash_get_group_courses_list( $group_id ); 122 if( ! is_array( $g_course_list ) ) { 123 124 $response['status'] = 'false'; 125 $response['message'] = __( 'Course not found.', 'reset-course-progress-for-learndash' ); 126 echo json_encode( $response ); 127 wp_die(); 128 } 129 130 foreach( $g_course_list as $course_id ) { 131 132 $response['content'] .= '<option value="'.intval( $course_id ).'">'.esc_html( get_the_title( $course_id ) ).'</option>'; 133 } 134 135 $response['status'] = 'true'; 136 echo json_encode( $response ); 137 wp_die(); 138 } 139 112 echo json_encode( $response ) ; 113 wp_die(); 114 } 115 140 116 /** 141 117 * User reset by Users html content … … 143 119 public static function rcpl_group_tabs_html() { 144 120 121 $reset_in_progress = RCPL_Functions::get_disabled_class( 'rcpl_reset_by_groups' ); 145 122 ?> 146 123 <div class="rcpl-wrap"> … … 149 126 150 127 <!-- page tab heading --> 151 <?php echo wp_kses( RCPL_Functions::tab_heading( 'Group' ), RCPL_Functions::allowed_html() ); ?> 128 <?php 129 echo wp_kses( RCPL_Functions::tab_heading( 'Group' ), RCPL_Functions::allowed_html() ) ; 130 ?> 152 131 <!-- end page tab heading --> 153 132 154 133 <!-- loader on page reload --> 155 <?php echo wp_kses( RCPL_Functions::loader_on_page_reload(), RCPL_Functions::allowed_html() ); ?> 134 <?php 135 echo wp_kses( RCPL_Functions::loader_on_page_reload(), RCPL_Functions::allowed_html() ) ; 136 ?> 156 137 <!-- end loader on page reload --> 157 138 158 139 <!-- Ajax Success message html --> 159 <?php echo wp_kses( RCPL_Functions::ajax_success_message_html(), RCPL_Functions::allowed_html() ); ?> 140 <?php 141 echo wp_kses( RCPL_Functions::ajax_success_message_html(), RCPL_Functions::allowed_html() ) ; 142 ?> 160 143 <!-- End ajax success message html --> 161 144 162 145 <div class="rcpl-form-content"> 163 164 <!-- group dropdown html --> 165 <?php echo wp_kses( RCPL_Functions::get_group_dropdown_html(), RCPL_Functions::allowed_html() ); ?> 166 <!-- end group dropdown html --> 167 168 <!-- Get reset rules html --> 169 <?php echo wp_kses( RCPL_Functions::get_reset_rules_html(), RCPL_Functions::allowed_html() ); ?> 170 <!-- End reset rules html --> 171 172 <!-- group course dropdown --> 173 <?php echo wp_kses( RCPL_Functions::fetching_group_course_html(), RCPL_Functions::allowed_html() ); ?> 174 <!-- end group course dropdown --> 175 176 <input type="button" class="rcpl-reset-by-group button button-primary" value="<?php _e( 'Reset Now', 'reset-course-progress-for-learndash' ); ?>" name="g_rcpl_submit_settings" /> 146 <div class="rcpl-from-material <?php 147 echo sanitize_html_class( $reset_in_progress ) ; 148 ?>"> 149 <input type="hidden" class="rcpl-save-group-ids" name="rcpl_save_group_ids[]" value=""> 150 151 <?php 152 ?> 153 154 <!-- group dropdown html --> 155 <?php 156 echo wp_kses( RCPL_Functions::get_group_dropdown_html( '' ), RCPL_Functions::allowed_html() ) ; 157 ?> 158 <!-- end group dropdown html --> 159 160 <?php 161 ?> 162 163 <!-- Get reset rules html --> 164 <?php 165 echo wp_kses( RCPL_Functions::get_reset_rules_html(), RCPL_Functions::allowed_html() ) ; 166 ?> 167 <!-- End reset rules html --> 168 169 <?php 170 ?> 171 172 <!-- group course dropdown --> 173 <?php 174 echo wp_kses( RCPL_Functions::fetching_group_course_html(), RCPL_Functions::allowed_html() ) ; 175 ?> 176 <!-- end group course dropdown --> 177 178 <?php 179 ?> 180 </div> 181 182 <!-- Reset message html --> 183 <?php 184 echo wp_kses( RCPL_Functions::reset_note_message_html( 'groups', $reset_in_progress, 'group' ), RCPL_Functions::allowed_html() ) ; 185 ?> 186 <!-- end reset message html --> 187 188 <div class="rcpl-form-actions <?php 189 echo sanitize_html_class( $reset_in_progress ) ; 190 ?>"> 191 <input type="button" class="rcpl-reset-by-group button button-primary" value="<?php 192 _e( 'Reset Now', 'reset-course-progress-for-learndash' ); 193 ?>" name="g_rcpl_submit_settings" /> 194 195 <?php 196 /** 197 * Fired after reset button 198 * 199 * @param users ( tab ) 200 */ 201 do_action( 'rcpl_after_reset_button', 'groups' ); 202 ?> 203 </div> 177 204 </div> 178 205 </div> 179 206 </div> 180 <?php 181 } 207 <?php 208 } 209 182 210 } 183 211 -
reset-course-progress-for-learndash/trunk/includes/class-reset-by-role.php
r2619924 r2661450 5 5 * Do not allow directly accessing this file. 6 6 */ 7 8 if( ! defined( 'ABSPATH' ) ) exit; 7 if ( !defined( 'ABSPATH' ) ) { 8 exit; 9 } 9 10 10 11 /** … … 13 14 class Reset_by_User_Role { 14 15 15 private static $instance = null; 16 16 private static $instance = null ; 17 17 /** 18 18 * @since 1.0 … … 20 20 */ 21 21 public static function instance() { 22 23 if ( is_null( self::$instance ) && ! ( self::$instance instanceof Reset_by_User_Role ) ) { 24 25 self::$instance = new self; 26 22 23 if ( is_null( self::$instance ) && !self::$instance instanceof Reset_by_User_Role ) { 24 self::$instance = new self(); 27 25 self::$instance->hooks(); 28 26 } 29 27 30 28 return self::$instance; 31 29 } 32 33 /** 34 * Shortcodehooks30 31 /** 32 * Plugin hooks 35 33 */ 36 34 private function hooks() { 37 35 38 add_action( 'admin_post_rcpl_submit_action', [ $this, 'rcpl_reset_user_role_data' ] );39 36 add_action( 'wp_ajax_rcpl_reset_course_by_roles', [ $this, 'rcpl_reset_course_progress_by_user_role' ] ); 40 } 41 37 add_action( 'rcpl_reset_by_roles', [ $this, 'rcpl_cron_reset_by_user_roles' ], 10, 1 ); 38 } 39 40 /** 41 * Course reset using cron job 42 * 43 * @param $args 44 */ 45 public function rcpl_cron_reset_by_user_roles( $args ) { 46 47 $user_id = $args['user_id']; 48 $selected_rule = $args['reset_rule']; 49 $course_ids = $args['course_ids']; 50 foreach ( $course_ids as $course_id ) { 51 RCPL_Functions::rcpl_course_resets( $course_id, $user_id ); 52 } 53 } 54 42 55 /** 43 56 * Reset users course progress with user roles : Ajax … … 45 58 public function rcpl_reset_course_progress_by_user_role() { 46 59 60 check_ajax_referer( 'rcpl_ajax_nonce', 'security' ); 47 61 $response = []; 48 49 62 $course_ids = ''; 50 $selected_rule = isset( $_POST['reset_rule'] ) ? sanitize_text_field( $_POST['reset_rule'] ) : ''; 51 if( empty( $selected_rule ) ) { 63 $selected_rule = ( isset( $_POST['reset_rule'] ) ? sanitize_text_field( $_POST['reset_rule'] ) : '' ); 64 65 if ( empty($selected_rule) ) { 52 66 53 67 $response['status'] = 'false'; 54 68 $response['message'] = __( 'Reset rule not found.', 'reset-course-progress-for-learndash' ); 55 echo json_encode( $response ); 56 wp_die(); 57 } 58 59 if( 'select_courses' == $selected_rule ) { 60 $course_ids = isset( $_POST['course_ids'] ) ? rest_sanitize_array( $_POST['course_ids'] ) : []; 61 62 } elseif( 'all_courses' == $selected_rule ) { 63 69 echo json_encode( $response ) ; 70 wp_die(); 71 } 72 73 74 if ( 'select_courses' == $selected_rule ) { 75 $course_ids = ( isset( $_POST['course_ids'] ) ? rest_sanitize_array( $_POST['course_ids'] ) : [] ); 76 } elseif ( 'all_courses' == $selected_rule ) { 64 77 $course_ids = RCPL_Functions::get_ids_of_all_courses(); 65 78 } 66 79 67 80 $course_ids = array_map( 'intval', $course_ids ); 68 if( empty( $course_ids ) ) { 69 81 if ( empty( $course_ids ) ) { 70 82 $response['status'] = 'false'; 71 83 $response['message'] = __( 'Course Ids rule not found.', 'reset-course-progress-for-learndash' ); 72 echo json_encode( $response ); 73 wp_die(); 74 } 75 76 $user_roles = isset( $_POST['target_id'] ) ? rest_sanitize_array( $_POST['target_id'] ) : []; 77 if( empty( $user_roles ) ) { 78 84 echo json_encode( $response ) ; 85 wp_die(); 86 } 87 88 $user_roles = ( isset( $_POST['target_id'] ) ? rest_sanitize_array( $_POST['target_id'] ) : [] ); 89 if ( empty( $user_roles ) ) { 79 90 $response['status'] = 'false'; 80 91 $response['message'] = __( 'User roles not found.', 'reset-course-progress-for-learndash' ); 81 echo json_encode( $response ); 82 wp_die(); 83 } 84 85 $users = RCPL_Functions::get_object_of_all_users(); 86 if( empty( $users ) ) { 87 92 echo json_encode( $response ) ; 93 wp_die(); 94 } 95 96 $users = RCPL_Functions::get_all_user_ids( $user_roles ); 97 if ( empty( $users ) ) { 88 98 $response['status'] = 'false'; 89 99 $response['message'] = __( 'Users object not found.', 'reset-course-progress-for-learndash' ); 90 echo json_encode( $response ); 91 wp_die(); 92 } 93 94 foreach( $users as $user ) { 95 96 foreach( $user_roles as $user_role ) { 97 98 if( ! RCPL_Functions::has_user_role( (int) $user->ID, $user_role ) ) { 99 continue; 100 } 101 102 foreach( $course_ids as $course_id ) { 103 104 RCPL_Functions::rcpl_course_resets( $course_id, (int) $user->ID ); 105 } 106 } 107 } 108 100 echo json_encode( $response ) ; 101 wp_die(); 102 } 103 104 $p_args = []; 105 foreach ( $users as $key => $user ) { 106 107 $user_id = (int) $user; 108 $f_args = [ 109 'user_id' => $user_id, 110 'reset_rule' => $selected_rule, 111 'course_ids' => $course_ids, 112 ]; 113 $args = array_merge( $f_args, $p_args ); 114 RCPL_Functions::create_single_events( $key, 'rcpl_reset_by_roles', $args ); 115 RCPL_Functions::update_cron_event_total_count( 'rcpl_reset_by_roles' ); 116 } 109 117 $response['status'] = 'true'; 110 echo json_encode( $response );118 echo json_encode( $response ) ; 111 119 wp_die(); 112 120 } 113 121 114 122 /** 115 123 * User reset by role html content … … 117 125 public static function rcpl_user_role_tabs_html() { 118 126 127 $reset_in_progress = RCPL_Functions::get_disabled_class( 'rcpl_reset_by_roles' ); 119 128 ?> 120 129 <div class="rcpl-wrap"> … … 123 132 124 133 <!-- page tab heading --> 125 <?php echo wp_kses( RCPL_Functions::tab_heading( 'User Roles' ), RCPL_Functions::allowed_html() ); ?> 134 <?php 135 echo wp_kses( RCPL_Functions::tab_heading( 'User Roles' ), RCPL_Functions::allowed_html() ) ; 136 ?> 126 137 <!-- end page tab heading --> 127 138 128 139 <!-- Ajax Success message html --> 129 <?php echo wp_kses( RCPL_Functions::ajax_success_message_html(), RCPL_Functions::allowed_html() ); ?> 140 <?php 141 echo wp_kses( RCPL_Functions::ajax_success_message_html(), RCPL_Functions::allowed_html() ) ; 142 ?> 130 143 <!-- End ajax success message html --> 131 144 132 145 <!-- loader on page reload --> 133 <?php echo wp_kses( RCPL_Functions::loader_on_page_reload(), RCPL_Functions::allowed_html() ); ?> 146 <?php 147 echo wp_kses( RCPL_Functions::loader_on_page_reload(), RCPL_Functions::allowed_html() ) ; 148 ?> 134 149 <!-- end loader on page reload --> 135 150 136 151 <div class="rcpl-form-content"> 137 138 <!-- user role dropdown --> 139 <?php echo wp_kses( RCPL_Functions::get_user_role_dropdown_html(), RCPL_Functions::allowed_html() ); ?> 140 <!-- end user role dropdown --> 152 <div class="rcpl-from-material <?php 153 echo sanitize_html_class( $reset_in_progress ) ; 154 ?>"> 155 <?php 156 ?> 157 158 <!-- user role dropdown --> 159 <?php 160 echo wp_kses( RCPL_Functions::get_user_role_dropdown_html(), RCPL_Functions::allowed_html() ) ; 161 ?> 162 <!-- end user role dropdown --> 163 164 <?php 165 ?> 166 167 <!-- Get reset rules html --> 168 <?php 169 echo wp_kses( RCPL_Functions::get_reset_rules_html(), RCPL_Functions::allowed_html() ) ; 170 ?> 171 <!-- End reset rules html --> 172 173 <?php 174 ?> 175 176 <!-- course dropdown --> 177 <?php 178 echo wp_kses( RCPL_Functions::get_course_field_dropdown_html(), RCPL_Functions::allowed_html() ) ; 179 ?> 180 <!-- end course dropdown --> 181 182 <?php 183 ?> 184 </div> 141 185 142 <!-- Get reset rules html --> 143 <?php echo wp_kses( RCPL_Functions::get_reset_rules_html(), RCPL_Functions::allowed_html() ); ?> 144 <!-- End reset rules html --> 145 146 <!-- course dropdown --> 147 <?php echo wp_kses( RCPL_Functions::get_course_field_dropdown_html(), RCPL_Functions::allowed_html() ); ?> 148 <!-- end course dropdown --> 149 150 <input class="rcpl-reset-by-roles button button-primary" type="button" class="button button-primary" value="<?php _e( 'Reset Now', 'reset-course-progress-for-learndash' ); ?>" name="rcpl_submit_settings" /> 186 <!-- Reset message html --> 187 <?php 188 echo wp_kses( RCPL_Functions::reset_note_message_html( 'roles', $reset_in_progress, 'user role' ), RCPL_Functions::allowed_html() ) ; 189 ?> 190 <!-- end reset message html --> 191 192 <div class="rcpl-form-actions <?php 193 echo sanitize_html_class( $reset_in_progress ) ; 194 ?>"> 195 <input class="rcpl-reset-by-roles button button-primary" type="button" class="button button-primary" value="<?php 196 _e( 'Reset Now', 'reset-course-progress-for-learndash' ); 197 ?>" name="rcpl_submit_settings" /> 198 199 <?php 200 /** 201 * Fired after reset button 202 * 203 * @param users ( tab ) 204 */ 205 do_action( 'rcpl_after_reset_button', 'roles' ); 206 ?> 207 </div> 151 208 </div> 152 209 </div> 153 210 </div> 154 <?php 155 } 211 <?php 212 } 213 156 214 } 157 215 -
reset-course-progress-for-learndash/trunk/includes/class-reset-by-users.php
r2619924 r2661450 5 5 * Do not allow directly accessing this file. 6 6 */ 7 8 if( ! defined( 'ABSPATH' ) ) exit; 7 if ( !defined( 'ABSPATH' ) ) { 8 exit; 9 } 9 10 10 11 /** … … 13 14 class Reset_by_Users { 14 15 15 private static $instance = null;16 private static $instance = null ; 16 17 17 18 /** … … 20 21 */ 21 22 public static function instance() { 22 23 if ( is_null( self::$instance ) && ! ( self::$instance instanceof Reset_by_Users ) ) { 24 25 self::$instance = new self; 26 23 24 if ( is_null( self::$instance ) && !self::$instance instanceof Reset_by_Users ) { 25 self::$instance = new self(); 27 26 self::$instance->hooks(); 28 27 } 29 28 30 29 return self::$instance; 31 30 } 32 33 /** 34 * Shortcodehooks31 32 /** 33 * Plugin hooks 35 34 */ 36 35 private function hooks() { 37 36 38 37 add_action( 'wp_ajax_rcpl_reset_course_by_users', [ $this, 'rcpl_reset_course_procress_by_users' ] ); 39 } 40 38 add_action( 'rcpl_reset_by_users', [ $this, 'rcpl_cron_reset_by_user' ], 10, 1 ); 39 } 40 41 /** 42 * Reset course using cron job 43 * 44 * @param $args 45 */ 46 public function rcpl_cron_reset_by_user( $args ) { 47 48 @set_time_limit( 3600 ); 49 $user_id = $args['user_id']; 50 $selected_rule = $args['reset_rule']; 51 $course_ids = $args['course_ids']; 52 foreach ( $course_ids as $course_id ) { 53 RCPL_Functions::rcpl_course_resets( $course_id, $user_id ); 54 } 55 } 56 41 57 /** 42 58 * Reset users course progress with users : Ajax … … 44 60 public function rcpl_reset_course_procress_by_users() { 45 61 62 check_ajax_referer( 'rcpl_ajax_nonce', 'security' ); 46 63 $response = []; 47 48 $user_ids = isset( $_POST['target_id'] ) ? rest_sanitize_array( $_POST['target_id'] ) : []; 64 $user_ids = ''; 65 $user_ids = ( isset( $_POST['target_id'] ) ? rest_sanitize_array( $_POST['target_id'] ) : [] ); 66 67 if ( empty($user_ids) ) { 68 $response['status'] = 'false'; 69 $response['message'] = __( 'User Ids not found.', 'reset-course-progress-for-learndash' ); 70 echo json_encode( $response ) ; 71 wp_die(); 72 } 73 49 74 $user_ids = array_map( 'intval', $user_ids ); 50 if( empty( $user_ids ) ) { 51 52 $response['status'] = 'false'; 53 $response['message'] = __( 'User IDs not found.', 'reset-course-progress-for-learndash' ); 54 echo json_encode( $response ); 55 wp_die(); 56 } 57 58 $course_ids = ''; 59 $selected_rule = isset( $_POST['reset_rule'] ) ? sanitize_text_field( $_POST['reset_rule'] ) : ''; 60 if( empty( $selected_rule ) ) { 61 75 $selected_rule = ( isset( $_POST['reset_rule'] ) ? sanitize_text_field( $_POST['reset_rule'] ) : '' ); 76 77 if ( empty($selected_rule) ) { 62 78 $response['status'] = 'false'; 63 79 $response['message'] = __( 'Reset rule not found.', 'reset-course-progress-for-learndash' ); 64 echo json_encode( $response );80 echo json_encode( $response ) ; 65 81 wp_die(); 66 82 } 67 68 if( 'select_courses' == $selected_rule ) { 69 70 $course_ids = isset( $_POST['course_ids'] ) ? rest_sanitize_array( $_POST['course_ids'] ) : []; 71 72 } elseif( 'all_courses' == $selected_rule ) { 73 83 84 $course_ids = ''; 85 86 if ( 'select_courses' == $selected_rule ) { 87 $course_ids = ( isset( $_POST['course_ids'] ) ? rest_sanitize_array( $_POST['course_ids'] ) : [] ); 88 } elseif ( 'all_courses' == $selected_rule ) { 74 89 $course_ids = RCPL_Functions::get_ids_of_all_courses(); 75 90 } 76 91 77 92 $course_ids = array_map( 'intval', $course_ids ); 78 if( empty( $course_ids ) ) { 79 80 $response['status'] = 'false'; 81 $response['message'] = __( 'Course Ids rule not found.', 'reset-course-progress-for-learndash' ); 82 echo json_encode( $response ); 83 wp_die(); 84 } 85 86 foreach( $user_ids as $user_id ) { 87 88 foreach( $course_ids as $course_id ) { 89 90 RCPL_Functions::rcpl_course_resets( $course_id, $user_id ); 91 } 93 $p_args = []; 94 foreach ( $user_ids as $key => $user_id ) { 95 $f_args = [ 96 'user_id' => $user_id, 97 'reset_rule' => $selected_rule, 98 'course_ids' => $course_ids, 99 ]; 100 $args = array_merge( $f_args, $p_args ); 101 RCPL_Functions::create_single_events( $key, 'rcpl_reset_by_users', $args ); 102 RCPL_Functions::update_cron_event_total_count( 'rcpl_reset_by_users' ); 92 103 } 93 104 94 105 $response['status'] = 'true'; 95 echo json_encode( $response );106 echo json_encode( $response ) ; 96 107 wp_die(); 97 108 } 98 109 99 110 /** 100 111 * User reset by Users html content … … 102 113 public static function rcpl_users_tabs_html() { 103 114 115 $reset_in_progress = RCPL_Functions::get_disabled_class( 'rcpl_reset_by_users' ); 104 116 ?> 105 117 <div class="rcpl-wrap"> … … 108 120 109 121 <!-- page tab heading --> 110 <?php echo wp_kses( RCPL_Functions::tab_heading( 'Users' ), RCPL_Functions::allowed_html() ); ?> 122 <?php 123 echo wp_kses( RCPL_Functions::tab_heading( 'Users' ), RCPL_Functions::allowed_html() ) ; 124 ?> 111 125 <!-- end page tab heading --> 112 126 113 127 <!-- Ajax Success message html --> 114 <?php echo wp_kses( RCPL_Functions::ajax_success_message_html(), RCPL_Functions::allowed_html() ); ?> 128 <?php 129 echo wp_kses( RCPL_Functions::ajax_success_message_html(), RCPL_Functions::allowed_html() ) ; 130 ?> 115 131 <!-- End ajax success message html --> 116 132 117 133 <!-- loader on page reload --> 118 <?php echo wp_kses( RCPL_Functions::loader_on_page_reload(), RCPL_Functions::allowed_html() ); ?> 134 <?php 135 echo wp_kses( RCPL_Functions::loader_on_page_reload(), RCPL_Functions::allowed_html() ) ; 136 ?> 119 137 <!-- end loader on page reload --> 120 138 121 139 <div class="rcpl-form-content"> 122 123 <!-- users dropdown html --> 124 <?php echo wp_kses( RCPL_Functions::get_users_dropdown_html(), RCPL_Functions::allowed_html() ); ?> 125 <!-- end users dropdown html --> 126 127 <!-- Get reset rules html --> 128 <?php echo wp_kses( RCPL_Functions::get_reset_rules_html(), RCPL_Functions::allowed_html() ); ?> 129 <!-- End reset rules html --> 130 131 <!-- course dropdown --> 132 <?php echo wp_kses( RCPL_Functions::get_course_field_dropdown_html(), RCPL_Functions::allowed_html() ); ?> 133 <!-- end course dropdown --> 134 135 <input type="button" class="rcpl-reset-by-users button button-primary" value="<?php _e( 'Reset Now', 'reset-course-progress-for-learndash' ); ?>" name="u_rcpl_submit_settings" /> 140 <div class="rcpl-from-material <?php 141 echo sanitize_html_class( $reset_in_progress ) ; 142 ?>"> 143 <input type="hidden" class="rcpl-save-user-ids" name="rcpl_save_user_ids[]" value=""> 144 <?php 145 ?> 146 147 <!-- users dropdown html --> 148 <?php 149 echo wp_kses( RCPL_Functions::get_users_dropdown_html(), RCPL_Functions::allowed_html() ) ; 150 ?> 151 <!-- end users dropdown html --> 152 153 <?php 154 ?> 155 156 <!-- Get reset rules html --> 157 <?php 158 echo wp_kses( RCPL_Functions::get_reset_rules_html(), RCPL_Functions::allowed_html() ) ; 159 ?> 160 <!-- End reset rules html --> 161 162 <?php 163 ?> 164 165 <!-- course dropdown --> 166 <?php 167 echo wp_kses( RCPL_Functions::get_course_field_dropdown_html(), RCPL_Functions::allowed_html() ) ; 168 ?> 169 <!-- end course dropdown --> 170 171 <?php 172 ?> 173 </div> 174 175 <!-- Reset message html --> 176 <?php 177 echo wp_kses( RCPL_Functions::reset_note_message_html( 'users', $reset_in_progress, 'user' ), RCPL_Functions::allowed_html() ) ; 178 ?> 179 <!-- end reset message html --> 180 181 <div class="rcpl-form-actions <?php 182 echo sanitize_html_class( $reset_in_progress ) ; 183 ?>"> 184 <input type="button" class="rcpl-reset-by-users button button-primary" value="<?php 185 _e( 'Reset Now', 'reset-course-progress-for-learndash' ); 186 ?>" name="u_rcpl_submit_settings" /> 187 188 <?php 189 /** 190 * Fired after reset button 191 * 192 * @param users ( tab ) 193 */ 194 do_action( 'rcpl_after_reset_button', 'users' ); 195 ?> 196 </div> 136 197 </div> 137 198 </div> 138 199 </div> 139 <?php 200 <?php 140 201 } 141 202 } -
reset-course-progress-for-learndash/trunk/readme.txt
r2648872 r2661450 3 3 Tags: learndash, LMS, Reset progress, Reset course, reset course learndash, learndash rest by group 4 4 Requires at least: 5.0 5 Tested up to: 5.8. 15 Tested up to: 5.8.3 6 6 Requires PHP: 7.0 7 Stable tag: 1. 27 Stable tag: 1.3 8 8 License: GPLv3 9 9 License URI: License: https://www.gnu.org/licenses/quick-guide-gplv3.html … … 11 11 Helps you reset course progress by users, user roles, and groups for all or selected courses 12 12 13 [youtube https://www.youtube.com/watch?v=TBl_vuA1DXk] 14 13 15 == Description == 14 Reset Course Progress for LearnDash simplifies the way to reset course progress from your WordPress dashboard. You can reset the progress by users, user roles, and groups for all or selected courses with a single click. 15 16 [youtube https://www.youtube.com/watch?v=TBl_vuA1DXk] 16 LearnDash’s Reset Course Progress streamlines the process of resetting course progress from your WordPress dashboard. With a single click, you may reset the progress for all or selected courses by users, user roles, and groups. In the progress result tab, it also shows the reset status/result. 17 17 18 18 … … 31 31 32 32 ## Support: 33 We understand the need for a quality product backed by dedicated support that cares, we are here to listen to all your queries and help you make the most out of our plugin. 34 You can create [support topics in the official support forum](https://wordpress.org/support/plugin/reset-course-progress-for-learndash/), or [Connect with us](http://ldninjas.com/contact-us/). 33 We realise the importance of a high-quality product supported by attentive customer service; we’re here to answer any of your questions and help you get the most out of our plugin. You can create support topics [here](https://wordpress.org/support/plugin/reset-course-progress-for-learndash/), or contact us [here](http://ldninjas.com/contact-us/). 35 34 36 35 == Frequently Asked Questions == … … 62 61 == Changelog == 63 62 63 = 1.3 2022-01-21 = 64 * Fixed: Fixed page load time limit issue 65 * Added: Added a new tab to see the in queue reset progress 66 * Improved: UI/UX on learnDash standards. 67 * Improved: Code structure. 68 64 69 = 1.2 2021-10-26 = 65 70 * Added: Option to reset progress of all courses for specific users -
reset-course-progress-for-learndash/trunk/reset-course-progress-for-learndash.php
r2619924 r2661450 3 3 * Plugin Name: Reset Course Progress For LearnDash 4 4 * Description: This add-on helps you reset course progress by users, user roles, and groups for all or selected courses. 5 * Version: 1. 25 * Version: 1.3 6 6 * Author: LDninjas 7 7 * Author URI: ldninjas.com … … 10 10 */ 11 11 12 if( ! defined( 'ABSPATH' ) ) exit; 12 if ( !defined( 'ABSPATH' ) ) { 13 exit; 14 } 13 15 14 include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 16 include_once ABSPATH . 'wp-admin/includes/plugin.php'; 17 if ( function_exists( 'is_plugin_active' ) ) { 18 if ( is_plugin_active( 'sfwd-lms/sfwd_lms.php' ) ) { 19 20 if ( !function_exists( 'rcpfl_fs' ) ) { 15 21 16 if( function_exists( 'is_plugin_active' )) {22 function rcpfl_fs() { 17 23 18 if( is_plugin_active( 'sfwd-lms/sfwd_lms.php' ) ) { 24 global $rcpfl_fs ; 25 26 if ( !isset( $rcpfl_fs ) ) { 19 27 20 if ( ! function_exists( 'rcpfl_fs' ) ) { 21 // Create a helper function for easy SDK access. 22 function rcpfl_fs() { 23 global $rcpfl_fs; 24 25 if ( ! isset( $rcpfl_fs ) ) { 26 // Include Freemius SDK. 27 require_once dirname(__FILE__) . '/freemius/start.php'; 28 require_once dirname( __FILE__ ) . '/freemius/start.php'; 28 29 29 30 $rcpfl_fs = fs_dynamic_init( array( 30 'id' => '9013', 31 'slug' => 'reset-course-progress-for-learndash', 32 'type' => 'plugin', 33 'public_key' => 'pk_b8487fd6f4b0946d6f7df843ec028', 34 'is_premium' => false, 35 'has_addons' => false, 36 'has_paid_plans' => false, 37 'menu' => array( 38 'slug' => 'reset-course-progress-for-learndash', 39 'account' => false, 40 'parent' => array( 41 'slug' => 'learndash-lms', 31 'id' => '9013', 32 'slug' => 'reset-course-progress-for-learndash', 33 'premium_slug' => 'reset-course-progress-pro-for-learndash', 34 'type' => 'plugin', 35 'public_key' => 'pk_b8487fd6f4b0946d6f7df843ec028', 36 'is_premium' => false, 37 'premium_suffix' => 'Reset Course Progress Pro for LearnDash', 38 'has_addons' => false, 39 'has_paid_plans' => true, 40 'menu' => array( 41 'slug' => 'reset-course-progress-for-learndash', 42 'parent' => array( 43 'slug' => 'learndash_lms_overview', 42 44 ), 43 45 ), 46 47 'is_live' => true, 44 48 ) ); 45 49 } 46 50 47 51 return $rcpfl_fs; 48 52 } 49 50 // Init Freemius. 53 51 54 rcpfl_fs(); 52 // Signal that SDK was initiated.53 55 do_action( 'rcpfl_fs_loaded' ); 54 56 } 55 } 57 58 } 56 59 } 57 60 58 61 /** 59 62 * Reset_Course_Progress_For_LearnDash … … 61 64 class Reset_Course_Progress_For_LearnDash { 62 65 63 const VERSION = '1.2';66 const VERSION = '1.3' ; 64 67 65 68 /** 66 69 * @var self 67 70 */ 68 private static $instance = null;71 private static $instance = null ; 69 72 70 73 /** … … 73 76 */ 74 77 public static function instance() { 75 76 if ( is_null( self::$instance ) && ! ( self::$instance instanceof Reset_Course_Progress_For_LearnDash ) ) { 77 self::$instance = new self; 78 78 79 if ( is_null( self::$instance ) && !self::$instance instanceof Reset_Course_Progress_For_LearnDash ) { 80 self::$instance = new self(); 79 81 self::$instance->setup_constants(); 80 82 self::$instance->includes(); … … 83 85 return self::$instance; 84 86 } 85 87 86 88 /** 87 89 * Plugin Constants 88 */90 */ 89 91 private function setup_constants() { 90 92 91 93 /** 92 94 * Directory 93 */94 define( 'RCPL_DIR', plugin_dir_path ( __FILE__ ) );95 define( 'RCPL_DIR_FILE', RCPL_DIR . basename ( __FILE__ ) );96 define( 'RCPL_INCLUDES_DIR', trailingslashit ( RCPL_DIR . 'includes' ) );97 define( 'RCPL_TEMPLATES_DIR', trailingslashit ( RCPL_DIR . 'templates' ) );98 define( 'RCPL_BASE_DIR', plugin_basename( __FILE__));95 */ 96 define( 'RCPL_DIR', plugin_dir_path( __FILE__ ) ); 97 define( 'RCPL_DIR_FILE', RCPL_DIR . basename( __FILE__ ) ); 98 define( 'RCPL_INCLUDES_DIR', trailingslashit( RCPL_DIR . 'includes' ) ); 99 define( 'RCPL_TEMPLATES_DIR', trailingslashit( RCPL_DIR . 'templates' ) ); 100 define( 'RCPL_BASE_DIR', plugin_basename( __FILE__ ) ); 99 101 100 102 /** 101 103 * URLs 102 */ 103 define( 'RCPL_URL', trailingslashit ( plugins_url ( '', __FILE__ ) ) ); 104 define( 'RCPL_ASSETS_URL', trailingslashit ( RCPL_URL . 'assets' ) ); 104 */ 105 define( 'RCPL_URL', trailingslashit( plugins_url( '', __FILE__ ) ) ); 106 define( 'RCPL_ASSETS_URL', trailingslashit( RCPL_URL . 'assets' ) ); 107 108 /** 109 * Plugin version 110 */ 111 define( 'RCPL_VERSION', self::VERSION ); 105 112 } 106 113 107 114 /** 108 115 * Plugin requiered files … … 110 117 private function includes() { 111 118 112 if ( file_exists( RCPL_INCLUDES_DIR.'admin/class-rcpl-admin.php' ) ) {119 if ( file_exists( RCPL_INCLUDES_DIR . 'admin/class-rcpl-admin.php' ) ) { 113 120 require_once RCPL_INCLUDES_DIR . 'admin/class-rcpl-admin.php'; 114 } 121 } 115 122 116 if ( file_exists( RCPL_INCLUDES_DIR.'class-rcpl-functions.php' ) ) {123 if ( file_exists( RCPL_INCLUDES_DIR . 'class-rcpl-functions.php' ) ) { 117 124 require_once RCPL_INCLUDES_DIR . 'class-rcpl-functions.php'; 118 125 } 119 126 120 if ( file_exists( RCPL_INCLUDES_DIR.'class-reset-by-users.php' ) ) {127 if ( file_exists( RCPL_INCLUDES_DIR . 'class-reset-by-users.php' ) ) { 121 128 require_once RCPL_INCLUDES_DIR . 'class-reset-by-users.php'; 122 129 } 123 130 124 if ( file_exists( RCPL_INCLUDES_DIR.'class-reset-by-role.php' ) ) {131 if ( file_exists( RCPL_INCLUDES_DIR . 'class-reset-by-role.php' ) ) { 125 132 require_once RCPL_INCLUDES_DIR . 'class-reset-by-role.php'; 126 133 } 127 134 128 if ( file_exists( RCPL_INCLUDES_DIR.'class-reset-by-group.php' ) ) {135 if ( file_exists( RCPL_INCLUDES_DIR . 'class-reset-by-group.php' ) ) { 129 136 require_once RCPL_INCLUDES_DIR . 'class-reset-by-group.php'; 130 137 } 131 138 } 139 132 140 } 133 134 141 /** 135 142 * Display admin notifications if dependency not found. … … 137 144 function rcpl_ready() { 138 145 139 if ( !is_admin() ) {146 if ( !is_admin() ) { 140 147 return; 141 148 } 149 150 if ( !class_exists( 'SFWD_LMS' ) ) { 142 151 143 if( ! class_exists( 'SFWD_LMS' ) ) { 144 deactivate_plugins ( plugin_basename ( __FILE__ ), true ); 152 deactivate_plugins( plugin_basename( __FILE__ ), true ); 145 153 $class = 'notice is-dismissible error'; 146 154 $message = __( 'Reset Course Progress For Learndash Add-on requires Learndash Plugin to be activated.', 'reset-course-progress-for-learndash' ); 147 printf ( '<div id="message" class="%s"> <p>%s</p></div>', $class, $message );155 printf( '<div id="message" class="%s"> <p>%s</p></div>', $class, $message ); 148 156 } 149 157 } … … 153 161 */ 154 162 function RCPL() { 163 164 if ( !class_exists( 'SFWD_LMS' ) ) { 155 165 156 if ( ! class_exists( 'SFWD_LMS' ) ) {157 166 add_action( 'admin_notices', 'rcpl_ready' ); 158 167 return false; 159 168 } 160 169 161 170 return Reset_Course_Progress_For_LearnDash::instance(); 162 171 } 163 172 add_action( 'plugins_loaded', 'RCPL' ); 164
Note: See TracChangeset
for help on using the changeset viewer.