Home › Forums › Legacy Support › Support queries › Update Issues › WPLMS4 upgrade – legacy hooks support
- This topic has 3 replies, 2 voices, and was last updated 3 years, 7 months ago by Anshuman Sahu.
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
March 25, 2021 at 10:16 am #348383Makarand ManeSpectatorHi We are upgrading existing WPLMS 3.9 to 4. As we had did many customizations using hooks. I am sharing code below. Let me know which code can support or work in WPLMS 4? Below are customizations we did
- • Hide retake quiz button after finish quiz in a course
- • Hide Price after purchase a course
- • Hide notifications in admin panel
- • Show “rate this course” button after finish course
- • Added for email template by logan / function to retake quizzes
- • Hide badge and certificate in course page
- • Hide quizzes after finish course
- • Mark assigment completed to finish the unit
- • Hide results after finish quiz
- • Custom currency and currency symbol
- • Show students with badges list
/*1. Hide retake quiz button after finish quiz in a course */ add_shortcode('quiz_retake',function($atts){ if(!is_user_logged_in()) return; $user_id = get_current_user_id(); ob_start(); bp_course_quiz_retake_form($atts['quiz'],$user_id,$atts['course']); echo '<style>.prev_quiz_results{display:block !important;}</style>'; $return = ob_get_clean(); return $return; });
/* 2.Hide Price after purchase a course */ add_filter('wplms_course_credits','wplms_show_new_course_student_status',9999,2); function wplms_show_new_course_student_status($credits,$course_id){ if(is_user_logged_in() && function_exists('bp_course_get_user_course_status') && is_singular('course')){ $user_id=get_current_user_id(); $check=get_user_meta($user_id,$course_id,true); if(isset($check) && $check){ if($check < time()){ return '<a href="'.get_permalink($course_id).'"><strong>'.sprintf(__('EXPIRED %s COURSE','vibe'),'<span class="subs">').'</span></strong></a>'; } $check_course= bp_course_get_user_course_status($user_id,$course_id); if(isset($check_course) && is_numeric($check_course) && $check_course){ $credits = ''; } } } return $credits; }
/* 3. Hide notifications in admin panel */ add_action( 'pre_get_comments', 'wplms_remove_comments_admin_panel' ); function wplms_remove_comments_admin_panel( $query ){ if(is_admin()){ $page=get_current_screen(); if( $page->base =='edit-comments') $query->query_vars['post_type'] = array('post','unit','course','wplms-assignment','product'); } return $query; }
/* 4. Show “rate this course” button after finish course*/ add_action('wplms_before_course_description',function (){ add_filter( 'get_post_metadata', 'myplugin_get_foo', 10, 4 ); }); function myplugin_get_foo( $null, $object_id, $meta_key, $single ) { if(!is_user_logged_in()) return $null; if ( 'vibe_course_review' == $meta_key ) { $user_id = get_current_user_id(); $status = bp_course_get_user_course_status($user_id,$object_id); if($status <= 3){ return array( 'H' ); } } return null; }
//5. Added for email template by logan / function to retake quizzes add_action('wplms_bulk_action',function ($action,$course_id,$member_ids){ if($action != 'added_students') return; foreach ($member_ids as $key => $member) { update_user_meta($member ,'user_subscribed_to_partial_free_course_'.$course_id,2); } },10,3); add_filter('bp_course_fetch_user_quiz_retake_count',function ($retake_count,$quiz_id,$user_id){ $passing_score = get_post_meta($quiz_id,'vibe_quiz_passing_score',true); if(isset($passing_score) && is_numeric($passing_score)){ $user_id = get_current_user_id(); $score = get_post_meta($quiz_id,$user_id,true); if($score > $passing_score){ return get_post_meta($quiz_id,'vibe_quiz_retakes',true); } } return $retake_count; },99999,3);
/* 6. Hide badge and certificate in course page */ add_filter('wplms_course_details_widget','remove_wplms_course_details_widget'); function remove_wplms_course_details_widget($course_details){ $key = array('badge','certificate'); foreach($key as $k){ unset($course_details[$k]); } return $course_details; }
/* 7. Hide quizzes after finish course */ add_filter('bp_course_get_course_curriculum',function($curriculum,$course_id){ if(is_user_logged_in()){ if(bp_course_is_member($course_id,get_current_user_id())){ if(bp_course_get_user_course_status(get_current_user_id(),$course_id) > 2){ $bp_course_template = BP_Course_Template::init(); $course_curriculum= $bp_course_template->get_curriculum($course_id); foreach($course_curriculum as $key=>$item_id){ if(get_post_type($item_id) == 'quiz'){ unset($course_curriculum[$key]); } } } } } return $course_curriculum; },10,2);
/* 8. Mark assigment completed to finish the unit */ add_filter('wplms_unit_mark_complete','wplms_assignments_force_unit_complete123',11,3); function wplms_assignments_force_unit_complete123($mark_unit_html,$unit_id,$course_id){ $flag=0; $assignment_locking = vibe_get_option('assignment_locking'); if(isset($assignment_locking) && $assignment_locking){ $unit_assignments = get_post_meta($unit_id,'vibe_assignment',false); if(is_Array($unit_assignments) && is_array($unit_assignments[0])){ $unit_assignments = vibe_sanitize($unit_assignments); } if(isset($unit_assignments) && is_array($unit_assignments)){ foreach($unit_assignments as $unit_assignment){ if(is_numeric($unit_assignment)){ $user_id = get_current_user_id(); $assignment_complete = get_post_meta($unit_assignment,$user_id,true); if(isset($assignment_complete) && $assignment_complete !=''){ }else{ $flag=1; break; } }//end-if }//end-for }else{ return $mark_unit_html; } }else{ return $mark_unit_html; } if($flag){ return '<a>'.__('FINISH ASSIGNMENT TO MARK UNIT COMPLETE','vibe').'</a>'; }else{ return '<a href="#" id="mark-complete" data-unit="'.$unit_id.'" class="unit_button">'._x('Mark Unit Complete','vibe').'</a>'; } }
/*9. Hide results after finish quiz*/ add_filter('wplms_user_quiz_results_link_action',function (){ return '#'; }); //add_filter('wplms_download_mod_stats_fields',array($this,'custom_wplms_download_mod_stats_fields'),10,1); //add_action('wplms_mod_stats_process',array($this,'custom_wplms_mod_stats_process'),10,7); function custom_wplms_download_mod_stats_fields($list){ $list['course-tag']= 'Etiqueta'; return $list; } function custom_wplms_mod_stats_process(&$csv_title, &$csv,&$i,&$id,&$user_id,&$field,&$post_type){ if($post_type != 'quiz') return; if($field != 'course-tag') // Ensures the field was checked. return; $title=__('Etiqueta','vibe'); if(!in_array($title,$csv_title)) $csv_title[$i]=$title; $user = get_userdata( $user_id ); $csv[$i][]= $user->course-tag; } add_filter('bp_email_get_salutation',function($salutation,$settings, $token){ return sprintf('Hola %s',$token); },10,3);
/** * 10. Custom currency and currency symbol */ add_filter( 'woocommerce_currencies', 'add_my_currency' ); function add_my_currency( $currencies ) { $currencies['ABC'] = __( 'Currency name', 'woocommerce' ); return $currencies; } add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2); function add_my_currency_symbol( $currency_symbol, $currency ) { switch( $currency ) { case 'MXN': $currency_symbol = 'MXN $'; break; case 'USD': $currency_symbol = 'USD $'; break; } return $currency_symbol; } /*sepa la bola*/ add_action('init','custom_hide_certificate_badge'); function custom_hide_certificate_badge(){ remove_action('bp_before_profile_content','wplms_show_profile_snapshot'); } add_action('bp_after_profile_content','wplms_show_profile_snapshot');
/*11. Show students with badges list*/ add_shortcode('students_with_badges',function($atts,$content=null){ global $wpdb; $return =''; $course_id = $atts['id']; if(empty($course_id)) $course_id = get_the_ID(); $results = $wpdb->get_results($wpdb->prepare("SELECT user_id from {$wpdb->usermeta} WHERE meta_key= %s AND meta_value LIKE %s",'badges','%:'.$course_id.';%')); if(!empty($results)){ $return .= '<div class="students_with_badges">'; foreach ($results as $key => $user) { $return .= '<div class="student">'; $return .= '<span>'.bp_core_get_user_displayname($user->user_id).'</span>'; $return .= '</div>'; } $return .= '</div>'; } $return .= '<style>.students_with_badges { display: flex; flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: center; } .students_with_badges .student img{ width:100px; height:100px; border-radius:50%; } .students_with_badges .student { display:flex; flex-direction:column; margin:1rem; justify-content:center; align-items:center; }</style>'; return $return; });
March 26, 2021 at 12:54 pm #348749Anshuman SahuKeymaster1 . will not work , it does work at php level but in react it is not handled . 2 . will work . 3 . will work . 4 . no need .done automatically . 5 . this snippet :
will work but this will not :add_action('wplms_bulk_action',function ($action,$course_id,$member_ids){ if($action != 'added_students') return; foreach ($member_ids as $key => $member) { update_user_meta($member ,'user_subscribed_to_partial_free_course_'.$course_id,2); } },10,3);
6 . will work with old course layouts , will not work as we do not show the details automatically now , you have to add blocks in course layout in elementor . 7 . It should work. 8 . . use this instead now :add_filter('bp_course_fetch_user_quiz_retake_count',function ($retake_count,$quiz_id,$user_id){ $passing_score = get_post_meta($quiz_id,'vibe_quiz_passing_score',true); if(isset($passing_score) && is_numeric($passing_score)){ $user_id = get_current_user_id(); $score = get_post_meta($quiz_id,$user_id,true); if($score > $passing_score){ return get_post_meta($quiz_id,'vibe_quiz_retakes',true); } } return $retake_count; },99999,3);
add_filter('wplms_assignment_lock',function($x){return 2;});
9 . not work . 10 . 11. will work .April 1, 2021 at 6:03 am #349959Makarand ManeSpectatorThis reply has been marked as private.April 1, 2021 at 1:22 pm #350079Anshuman SahuKeymaster1 . this code is actually a shortcode to show quiz_retakes .Now with react quizzes this wont work anymore and we have not supported this right now .We will have to check whether it will work or not. 9 . for this there is no more check results button there now . IF you wish to hide the results completely then you can enable "hide correct answer" settings from wp-admin -> lms > settings , -
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- The topic ‘WPLMS4 upgrade – legacy hooks support’ is closed to new replies.