Plugin Directory

Changeset 2661450


Ignore:
Timestamp:
01/21/2022 03:46:37 PM (4 years ago)
Author:
ldninjas
Message:
  • Fixed: Fixed page load time limit issue
  • Added: Added a new tab to see the in queue reset progress
  • Improved: UI/UX on learnDash standards.
  • Improved: Code structure.
Location:
reset-course-progress-for-learndash
Files:
14 added
4 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • reset-course-progress-for-learndash/trunk/assets/css/backend.css

    r2619924 r2661450  
    22    visibility: hidden;
    33    position: relative;
    4     height: 272px;
    5     max-height: 272px;
    64    padding: 10px 20px;
    75}
     
    1412}
    1513span.select2-container {
    16     width: 50% !important;
     14    width: 55% !important;
    1715    position: absolute;
    1816    left: 12%;
     17    /*top: 8px;*/
    1918}
    2019.nav-tab-wrapper {
     
    3534.rcpl-form-wrap {
    3635    clear: both;
    37     /*padding-left: 20px;*/
    3836    position: relative;
    3937}
     
    4644    min-width: 255px;
    4745    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);
    4947    background: #fff;
    5048}
    5149.rcpl-wrap .rcpl-wrapper {
    52     padding: 26px 0;
     50    padding: 15px 0;
     51    margin-bottom: 20px;
    5352    position: relative;
    5453}
     
    7170    line-height: 1.4;
    7271    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;
    8372}
    8473.select2-selection--single {
     
    124113    position: absolute;
    125114    left: 12%;
    126     top: 105%;
     115    top: 120%;
    127116    display: block;
    128117    color: #e13c3c;
     
    153142    width: 28px;
    154143}
    155 .rcpl-success-message span {
    156     color: #999999;
     144.rcpl-success-message .rcpl-loading-wrap {
     145    color: #008000;
    157146    font-size: 20px;
    158147    vertical-align: super;
    159148    position: relative;
    160149    margin-left: 5px;
     150    display: inline;
    161151}
    162152.rcpl-wrapper .rcpl-left {
     
    236226  }
    237227}
    238 /*** end enimated dot ***/ 
     228/*** end enimated dot ***/
    239229
    240230/* Tabs desing css  */
     
    311301    max-width: 200px !important;
    312302}
     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  
    44            init: function() {
    55                this.addLoaderOnPageLoad();
    6                 this.addExternalSelectBox();
    76                this.onChangeOnGroup();
    87                this.onChangeOnRuleOptions();
    98                this.resetCourseByUsers();
    109                this.resetCourseByUserRoles();
     10                this.onChangeUsersField();
    1111                this.resetCourseByGroup();
    1212            },
    1313
    1414            /**
    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
    1638             */
    1739            addLoaderOnPageLoad: function() {
    1840
    19                 window.onload = function(){
    20                    
     41                $( document ).ready( function() {
    2142                    $( '.rcpl-form-content' ).css( 'visibility', 'visible' );
    2243                    $( '.rcpl-page-loader' ).hide();
    23                 }
     44                });
    2445            },
    2546
     
    4061                        let parent = self.parents( '.rcpl-form-wrap' );
    4162
    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
    4869                        let resetRule = parent.find( '.rcpl-select-rules-option:checked' ).val();
    4970                        if( RCPLbackEnd.formValidation( resetRule, parent, '.rcpl-select-rules-option' ) ) {
    50                            
     71
    5172                            error++;
    5273                        }
     
    5778                            coursesIDs = parent.find( '.rcpl-select-course-list' ).val();
    5879                            if( RCPLbackEnd.formValidation( coursesIDs, parent, '.rcpl-select-course-list' ) ) {
    59                            
     80
    6081                                error++;
    6182                            }
    6283                        }
     84
     85                        let lessonIDs = '';
     86                        let topicIDs = '';
     87                        let quizID = '';
     88                        let lessonReset = false;
     89                        let topicReset = false;
     90                        let progressOption = '';
     91
     92                       
    6393
    6494                        if( error != 0 )
    6595                            return false;
    6696
    67                         RCPLbackEnd.exicuteAjaxAfterErrorRemove( '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            },
    71101
    72102            /**
     
    79109                    $( '.rcpl-reset-by-roles' ).on( 'click', function() {
    80110
    81                         console.log( $( '.rcpl-validate-msg' ).html( '' ) );
     111                        $( '.rcpl-validate-msg' ).html( '' );
    82112
    83113                        let error = 0;
     
    91121                            error++;
    92122                        }
    93                        
     123
    94124                        let resetRule = parent.find( '.rcpl-select-rules-option:checked' ).val();
    95125                        if( RCPLbackEnd.formValidation( resetRule, parent, '.rcpl-select-rules-option' ) ) {
    96                            
     126
    97127                            error++;
    98128                        }
     
    103133                            coursesIDs = parent.find( '.rcpl-select-course-list' ).val();
    104134                            if( RCPLbackEnd.formValidation( coursesIDs, parent, '.rcpl-select-course-list' ) ) {
    105                            
     135
    106136                                error++;
    107137                            }
    108138                        }
     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> */
    109169
    110170                        if( error != 0 )
    111171                            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 );
    115173                    } );
    116174                }
     
    133191                        let parent = self.parents( '.rcpl-form-wrap' );
    134192
    135                         let userIDs = parent.find( '.rcpl-select-user-list' ).val();
     193                       
     194
     195                        let userIDs = $( '.rcpl-save-user-ids' ).val();
    136196                        if( RCPLbackEnd.formValidation( userIDs, parent, '.rcpl-select-user-list' ) ) {
    137197
    138198                            error++;
    139199                        }
    140                        
     200
    141201                        let resetRule = parent.find( '.rcpl-select-rules-option:checked' ).val();
    142202                        if( RCPLbackEnd.formValidation( resetRule, parent, '.rcpl-select-rules-option' ) ) {
    143                            
     203
    144204                            error++;
    145205                        }
     
    150210                            coursesIDs = parent.find( '.rcpl-select-course-list' ).val();
    151211                            if( RCPLbackEnd.formValidation( coursesIDs, parent, '.rcpl-select-course-list' ) ) {
    152                            
     212
    153213                                error++;
    154214                            }
    155215                        }
     216
     217                        let progressOption = '';
     218                        let lessonIDs = '';
     219                        let topicIDs = '';
     220                        let quizID = '';
     221                        let lessonReset = false;
     222                        let topicReset = false;
     223
     224                       
    156225
    157226                        if( error != 0 ) {
     
    159228                        }
    160229
    161                         RCPLbackEnd.exicuteAjaxAfterErrorRemove( '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 );
    162231
    163232                    } );
     
    167236            /**
    168237             * Exicute Ajax functionality after error message.
    169              * 
     238             *
    170239             * @param action
    171240             * @param targetID
    172241             * @param resetRule
    173242             * @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?';
    176252
    177253                setTimeout( function() {
    178254
    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                    });
    195286
    196287                },50 );
     
    199290            /**
    200291             * Create Validation message
    201              * 
     292             *
    202293             * @param existsVal
    203294             * @param parent
     
    206297            formValidation: function( existsVal, parent, beforeClass ) {
    207298
    208                 if( '' == existsVal ) {
     299                if( '' == existsVal || ! existsVal ) {
    209300                    parent.find( beforeClass ).parents( '.rcpl-wrapper' ).find( '.rcpl-validate-msg' ).html( 'Please fill out this field.' );
    210                    
     301
    211302                    return true;
    212                 }   
     303                }
    213304            },
    214305
    215306            /**
    216307             * Alert message before/after ajax response
    217              * 
     308             *
    218309             * @param response
    219310             */
     
    230321                        console.log( jsonEncode.message );
    231322                    } 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 );
    238324                    }
    239325                }
     
    242328            /**
    243329             * Hide/show courses select field
     330             * Save course ids in hidden field
    244331             */
    245332            onChangeOnRuleOptions: function() {
     
    249336                    $( '.rcpl-select-rules-option' ).on( 'change', function() {
    250337
    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
    270403             */
    271404            onChangeOnGroup: function() {
    272405
    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                }
    330424            },
    331425        };
  • reset-course-progress-for-learndash/trunk/includes/admin/class-rcpl-admin.php

    r2619924 r2661450  
    1313class RCPL_Admin {
    1414
    15     const VERSION = '1.2';
    16 
    1715    /**
    1816     * @var self
     
    3129            self::$instance->hooks();
    3230        }
    33        
     31
    3432        return self::$instance;
    3533    }
     
    4442        add_filter( 'plugin_action_links_'. RCPL_BASE_DIR, [ $this, 'rcpl_plugin_setting_links' ] );
    4543        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();
    46172    }
    47173
     
    103229            'reset_by_users'        => __( 'Reset by Users', 'reset-course-progress-for-learndash' ),
    104230            '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' )
    106233        ];
    107234
    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;
    141261    }
    142262
     
    147267
    148268        $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() );
    150270
    151271        if ( $tab == 'reset_by_user_roles' ) {
     
    164284                Reset_by_Group::rcpl_group_tabs_html();
    165285            }   
     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            }
    166292        }
    167293    }
     
    177303        if( $screen ) {
    178304
    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' ) {
    180307
    181308                /**
    182309                 * enqueue admin css
    183310                 */
    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 );
    185312                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
    187315                /**
    188316                 * add slect2 js
    189317                 */
    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                ) );
    192326            }
    193327        } 
  • reset-course-progress-for-learndash/trunk/includes/class-rcpl-functions.php

    r2619924 r2661450  
    3030
    3131    /**
     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    /**
    32126     * Create html for tabs heading
    33127     *
     
    76170        $allowed_html = [
    77171            'div'   => [
    78                 'class'     => []
     172                'class'     => [],
     173                'data-user_id'  => [],
     174                'id'   => [],
    79175            ],
    80176            'label' => [
     
    106202                'src'      => []
    107203            ],
     204            'h1' => [
     205                'class'   => [],
     206            ],
     207            'a' => [
     208                'class'   => [],
     209                'href'    => []
     210            ]
    108211        ];
    109212
     
    114217     * Fetching group course dropdown html
    115218     */
    116     public function fetching_group_course_html() {
     219    public static function fetching_group_course_html() {
    117220       
    118221        ob_start();
    119 
    120222        ?>
    121223        <div class="rcpl-wrapper rcpl-select-course-fields">
    122224            <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">
    124226                <option disabled="disabled"><?php _e( 'Select Course', 'reset-course-progress-for-learndash' ); ?></option>
    125227            </select>
    126228            <div class="rcpl-validate-msg"></div>
    127             <div class="ajax-course-data-fetching"><?php _e( 'Fetching...', 'reset-course-progress-for-learndash' ); ?></div>
    128229        </div>
    129230        <?php
     
    138239     * Create group dropdown html
    139240     */
    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">
    147247            <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>
    160249            <div class="rcpl-validate-msg"></div>
    161250        </div>
     
    178267        <div class="rcpl-success-message">
    179268            <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.' ); ?>
    181270                <div class="rcpl-animated-dot">
    182271                    <div class="dot-pulse"></div>
    183272                </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>
    189274        </div>
    190275        <?php
     
    201286    public static function get_users_dropdown_html() {
    202287
    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">
    208291            <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             
    221294            </select>
    222295            <div class="rcpl-validate-msg"></div>
     
    237310        global $wp_roles;
    238311        ob_start();
    239 
    240         ?>
    241         <div class="rcpl-wrapper">
     312       
     313        ?>
     314        <div class="rcpl-wrapper rcpl-user-role-fields">
    242315            <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">
    244317                <option disabled="disabled"><?php _e( 'Select User Role', 'reset-course-progress-for-learndash' ); ?></option>
    245318                <?php
     
    274347    public static function get_course_field_dropdown_html() {
    275348
    276         $course_ids = self::get_ids_of_all_courses();
    277 
    278349        ob_start();
    279350        ?>
    280351        <div class="rcpl-wrapper rcpl-select-course-fields">
    281352            <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>
    294354            <div class="rcpl-validate-msg"></div>
    295355        </div>
     
    316376                <input checked="checked" type="radio" value="select_courses" class="rcpl-select-rules-option" name="rcpl_select_rules_option">
    317377                <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">
    319379                <span><?php _e( 'All courses', 'reset-course-progress-for-learndash' ); ?></span>
    320380            </div>
     
    351411
    352412    /**
    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;
    369439    }
    370440
     
    389459
    390460    /**
    391      * Check if user role exists
    392      *
    393      * @param $user_id
    394      */
    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     /**
    410461     * Reset LD course by schedule
    411462     *
     
    422473        if( $lesson_list ) {
    423474            foreach( $lesson_list as $lessons ) {
    424                
     475
    425476                /**
    426477                 * Mark lesson as incomplete
  • reset-course-progress-for-learndash/trunk/includes/class-reset-by-group.php

    r2619924 r2661450  
    55 * Do not allow directly accessing this file.
    66 */
    7 
    8 if( ! defined( 'ABSPATH' ) ) exit;
     7if ( !defined( 'ABSPATH' ) ) {
     8    exit;
     9}
    910
    1011/**
     
    1314class Reset_by_Group {
    1415
    15     private static $instance = null;
     16    private static  $instance = null ;
    1617
    1718    /**
     
    2021     */
    2122    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();
    2726            self::$instance->hooks();
    2827        }
    29 
     28       
    3029        return self::$instance;
    3130    }
    32 
    33     /**
    34      * Shortcode hooks
     31   
     32    /**
     33     * plugin hooks
    3534     */
    3635    private function hooks() {
    3736
    38         add_action( 'wp_ajax_rcpl_get_group_courses', [ $this, 'rcpl_fetch_group_courses' ] );
    3937        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   
    4256    /**
    4357     * Reset users course progress by group : Ajax
     
    4559    public function rcpl_reset_course_progress_by_group() {
    4660
     61        check_ajax_referer( 'rcpl_ajax_nonce', 'security' );
    4762        $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) ) {
    5266            $response['status'] = 'false';
    5367            $response['message'] = __( 'Group ID not found.', 'reset-course-progress-for-learndash' );
    54             echo json_encode( $response );
     68            echo  json_encode( $response ) ;
    5569            wp_die();
    5670        }
    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) ) {
    6176            $response['status'] = 'false';
    6277            $response['message'] = __( 'Reset rule not found.', 'reset-course-progress-for-learndash' );
    63             echo json_encode( $response );
     78            echo  json_encode( $response ) ;
    6479            wp_die();
    6580        }
    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 );
    9198                }
    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' );
    97109            }
    98110        }
    99 
    100111        $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   
    140116    /**
    141117     * User reset by Users html content
     
    143119    public static function rcpl_group_tabs_html() {
    144120
     121        $reset_in_progress = RCPL_Functions::get_disabled_class( 'rcpl_reset_by_groups' );
    145122        ?>
    146123        <div class="rcpl-wrap">
     
    149126
    150127                <!-- 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        ?>
    152131                <!-- end page tab heading -->
    153132
    154133                <!-- 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        ?>
    156137                <!-- end loader on page reload -->
    157138
    158139                <!-- 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        ?>
    160143                <!-- End ajax success message html -->
    161144
    162145                <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>
    177204                </div>
    178205            </div>
    179206        </div>
    180         <?php
    181     }
     207        <?php
     208    }
     209
    182210}
    183211
  • reset-course-progress-for-learndash/trunk/includes/class-reset-by-role.php

    r2619924 r2661450  
    55 * Do not allow directly accessing this file.
    66 */
    7 
    8 if( ! defined( 'ABSPATH' ) ) exit;
     7if ( !defined( 'ABSPATH' ) ) {
     8    exit;
     9}
    910
    1011/**
     
    1314class Reset_by_User_Role {
    1415
    15     private static $instance = null;
    16 
     16    private static  $instance = null ;
    1717    /**
    1818     * @since 1.0
     
    2020     */
    2121    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();
    2725            self::$instance->hooks();
    2826        }
    29 
     27       
    3028        return self::$instance;
    3129    }
    32 
    33     /**
    34      * Shortcode hooks
     30   
     31    /**
     32     * Plugin hooks
    3533     */
    3634    private function hooks() {
    3735
    38         add_action( 'admin_post_rcpl_submit_action', [ $this, 'rcpl_reset_user_role_data' ] );
    3936        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   
    4255    /**
    4356     * Reset users course progress with user roles : Ajax
     
    4558    public function rcpl_reset_course_progress_by_user_role() {
    4659
     60        check_ajax_referer( 'rcpl_ajax_nonce', 'security' );
    4761        $response = [];
    48 
    4962        $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) ) {
    5266
    5367            $response['status'] = 'false';
    5468            $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 ) {
    6477            $course_ids = RCPL_Functions::get_ids_of_all_courses();
    6578        }
    66 
     79       
    6780        $course_ids = array_map( 'intval', $course_ids );
    68         if( empty( $course_ids ) ) {
    69 
     81        if ( empty( $course_ids ) ) {
    7082            $response['status'] = 'false';
    7183            $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 ) ) {
    7990            $response['status'] = 'false';
    8091            $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 ) ) {
    8898            $response['status'] = 'false';
    8999            $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        }
    109117        $response['status'] = 'true';
    110         echo json_encode( $response );
     118        echo  json_encode( $response ) ;
    111119        wp_die();
    112120    }
    113 
     121   
    114122    /**
    115123     * User reset by role html content
     
    117125    public static function rcpl_user_role_tabs_html() {
    118126
     127        $reset_in_progress = RCPL_Functions::get_disabled_class( 'rcpl_reset_by_roles' );
    119128        ?>
    120129        <div class="rcpl-wrap">
     
    123132
    124133                <!-- 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        ?>
    126137                <!-- end page tab heading -->
    127138
    128139                <!-- 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        ?>
    130143                <!-- End ajax success message html -->
    131144
    132145                <!-- 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        ?>
    134149                <!-- end loader on page reload -->
    135150
    136151                <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>
    141185                   
    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>
    151208                </div>
    152209            </div> 
    153210        </div>
    154         <?php
    155     }
     211        <?php
     212    }
     213
    156214}
    157215
  • reset-course-progress-for-learndash/trunk/includes/class-reset-by-users.php

    r2619924 r2661450  
    55 * Do not allow directly accessing this file.
    66 */
    7 
    8 if( ! defined( 'ABSPATH' ) ) exit;
     7if ( !defined( 'ABSPATH' ) ) {
     8    exit;
     9}
    910
    1011/**
     
    1314class Reset_by_Users {
    1415
    15     private static $instance = null;
     16    private static  $instance = null ;
    1617
    1718    /**
     
    2021     */
    2122    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();
    2726            self::$instance->hooks();
    2827        }
    29 
     28       
    3029        return self::$instance;
    3130    }
    32 
    33     /**
    34      * Shortcode hooks
     31   
     32    /**
     33     * Plugin hooks
    3534     */
    3635    private function hooks() {
    37        
     36
    3837        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   
    4157    /**
    4258     * Reset users course progress with users : Ajax
     
    4460    public function rcpl_reset_course_procress_by_users() {
    4561
     62        check_ajax_referer( 'rcpl_ajax_nonce', 'security' );
    4663        $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       
    4974        $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) ) {
    6278            $response['status'] = 'false';
    6379            $response['message'] = __( 'Reset rule not found.', 'reset-course-progress-for-learndash' );
    64             echo json_encode( $response );
     80            echo  json_encode( $response ) ;
    6581            wp_die();
    6682        }
    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 ) {
    7489            $course_ids = RCPL_Functions::get_ids_of_all_courses();
    7590        }
    76 
     91       
    7792        $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' );
    92103        }
    93104
    94105        $response['status'] = 'true';
    95         echo json_encode( $response );
     106        echo  json_encode( $response ) ;
    96107        wp_die();
    97108    }
    98 
     109   
    99110    /**
    100111     * User reset by Users html content
     
    102113    public static function rcpl_users_tabs_html() {
    103114
     115        $reset_in_progress = RCPL_Functions::get_disabled_class( 'rcpl_reset_by_users' );
    104116        ?>
    105117        <div class="rcpl-wrap">
     
    108120
    109121                <!-- 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        ?>
    111125                <!-- end page tab heading -->
    112126
    113127                <!-- 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        ?>
    115131                <!-- End ajax success message html -->
    116132
    117133                <!-- 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        ?>
    119137                <!-- end loader on page reload -->
    120138
    121139                <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>
    136197                </div>
    137198            </div>
    138199        </div>
    139         <?php
     200        <?php 
    140201    }
    141202}
  • reset-course-progress-for-learndash/trunk/readme.txt

    r2648872 r2661450  
    33Tags: learndash, LMS, Reset progress, Reset course, reset course learndash, learndash rest by group
    44Requires at least: 5.0
    5 Tested up to: 5.8.1
     5Tested up to: 5.8.3
    66Requires PHP: 7.0
    7 Stable tag: 1.2
     7Stable tag: 1.3
    88License: GPLv3
    99License URI: License: https://www.gnu.org/licenses/quick-guide-gplv3.html
     
    1111Helps you reset course progress by users, user roles, and groups for all or selected courses
    1212
     13[youtube https://www.youtube.com/watch?v=TBl_vuA1DXk]
     14
    1315== 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]
     16LearnDash’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.
    1717
    1818
     
    3131
    3232## 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/).
     33We 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/).
    3534
    3635== Frequently Asked Questions ==
     
    6261== Changelog ==
    6362
     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
    6469= 1.2 2021-10-26 =
    6570* 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  
    33 * Plugin Name: Reset Course Progress For LearnDash
    44 * Description: This add-on helps you reset course progress by users, user roles, and groups for all or selected courses.
    5  * Version: 1.2
     5 * Version: 1.3
    66 * Author: LDninjas
    77 * Author URI: ldninjas.com
     
    1010 */
    1111
    12 if( ! defined( 'ABSPATH' ) ) exit;
     12if ( !defined( 'ABSPATH' ) ) {
     13    exit;
     14}
    1315
    14 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
     16include_once ABSPATH . 'wp-admin/includes/plugin.php';
     17if ( function_exists( 'is_plugin_active' ) ) {
     18    if ( is_plugin_active( 'sfwd-lms/sfwd_lms.php' ) ) {
     19       
     20        if ( !function_exists( 'rcpfl_fs' ) ) {
    1521
    16 if( function_exists( 'is_plugin_active' ) ) {
     22            function rcpfl_fs() {
    1723
    18     if( is_plugin_active( 'sfwd-lms/sfwd_lms.php' ) ) {
     24                global  $rcpfl_fs ;
     25               
     26                if ( !isset( $rcpfl_fs ) ) {
    1927
    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';
    2829
    2930                    $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',
    4244                            ),
    4345                        ),
     46
     47                        'is_live'        => true,
    4448                    ) );
    4549                }
    46 
     50               
    4751                return $rcpfl_fs;
    4852            }
    49 
    50             // Init Freemius.
     53           
    5154            rcpfl_fs();
    52             // Signal that SDK was initiated.
    5355            do_action( 'rcpfl_fs_loaded' );
    5456        }
    55     } 
     57   
     58    }
    5659}
    57  
     60
    5861/**
    5962 * Reset_Course_Progress_For_LearnDash
     
    6164class Reset_Course_Progress_For_LearnDash {
    6265
    63     const VERSION = '1.2';
     66    const  VERSION = '1.3' ;
    6467
    6568    /**
    6669     * @var self
    6770     */
    68     private static $instance = null;
     71    private static  $instance = null ;
    6972
    7073    /**
     
    7376     */
    7477    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();
    7981            self::$instance->setup_constants();
    8082            self::$instance->includes();
     
    8385        return self::$instance;
    8486    }
    85 
     87   
    8688    /**
    8789     * Plugin Constants
    88     */
     90     */
    8991    private function setup_constants() {
    9092
    9193        /**
    9294         * 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__ ) );
    99101
    100102        /**
    101103         * 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 );
    105112    }
    106 
     113   
    107114    /**
    108115     * Plugin requiered files
     
    110117    private function includes() {
    111118
    112         if( file_exists( RCPL_INCLUDES_DIR.'admin/class-rcpl-admin.php' ) ) {
     119        if ( file_exists( RCPL_INCLUDES_DIR . 'admin/class-rcpl-admin.php' ) ) {
    113120            require_once RCPL_INCLUDES_DIR . 'admin/class-rcpl-admin.php';
    114         }       
     121        }
    115122
    116         if( file_exists( RCPL_INCLUDES_DIR.'class-rcpl-functions.php' ) ) {
     123        if ( file_exists( RCPL_INCLUDES_DIR . 'class-rcpl-functions.php' ) ) {
    117124            require_once RCPL_INCLUDES_DIR . 'class-rcpl-functions.php';
    118125        }
    119126
    120         if( file_exists( RCPL_INCLUDES_DIR.'class-reset-by-users.php' ) ) {
     127        if ( file_exists( RCPL_INCLUDES_DIR . 'class-reset-by-users.php' ) ) {
    121128            require_once RCPL_INCLUDES_DIR . 'class-reset-by-users.php';
    122129        }
    123130
    124         if( file_exists( RCPL_INCLUDES_DIR.'class-reset-by-role.php' ) ) {
     131        if ( file_exists( RCPL_INCLUDES_DIR . 'class-reset-by-role.php' ) ) {
    125132            require_once RCPL_INCLUDES_DIR . 'class-reset-by-role.php';
    126133        }
    127134
    128         if( file_exists( RCPL_INCLUDES_DIR.'class-reset-by-group.php' ) ) {
     135        if ( file_exists( RCPL_INCLUDES_DIR . 'class-reset-by-group.php' ) ) {
    129136            require_once RCPL_INCLUDES_DIR . 'class-reset-by-group.php';
    130137        }
    131138    }
     139
    132140}
    133 
    134141/**
    135142 * Display admin notifications if dependency not found.
     
    137144function rcpl_ready() {
    138145
    139     if( ! is_admin() ) {
     146    if ( !is_admin() ) {
    140147        return;
    141148    }
     149   
     150    if ( !class_exists( 'SFWD_LMS' ) ) {
    142151
    143     if( ! class_exists( 'SFWD_LMS' ) ) {
    144         deactivate_plugins ( plugin_basename ( __FILE__ ), true );
     152        deactivate_plugins( plugin_basename( __FILE__ ), true );
    145153        $class = 'notice is-dismissible error';
    146154        $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 );
    148156    }
    149157}
     
    153161 */
    154162function RCPL() {
     163   
     164    if ( !class_exists( 'SFWD_LMS' ) ) {
    155165
    156     if ( ! class_exists( 'SFWD_LMS' ) ) {
    157166        add_action( 'admin_notices', 'rcpl_ready' );
    158167        return false;
    159168    }
    160 
     169   
    161170    return Reset_Course_Progress_For_LearnDash::instance();
    162171}
    163172add_action( 'plugins_loaded', 'RCPL' );
    164 
Note: See TracChangeset for help on using the changeset viewer.