Skip to content

Instantly share code, notes, and snippets.

@MrVibe
MrVibe / functions.php
Last active August 30, 2020 17:36
Get top 15 quiz scorers
add_shortcode('wplms_quiz_top_scorers',function($atts,$content = null){
extract(shortcode_atts(array(
'count' => 5,
)));
global $wpdb;
add_action('wp_footer',function(){
if(!is_user_logged_in())
return;
$user_id = get_current_user_id();
$courses = bp_course_get_user_courses($user_id);
@MrVibe
MrVibe / functions.php
Created March 18, 2018 17:08
Restrict users from seeing course retake option if their marks are 85% or above
add_filter('wplms_course_retake_count',function($retakes,$course_id,$user_id){
$status = bp_course_get_user_course_status($user_id,$course_id);
if($status > 3){
$course_percentage = get_post_meta( $course_id,$user_id,true);
if($course_percentage >=85){
return 0;
}
}
return $retakes;
},10,3);
@MrVibe
MrVibe / functions.php
Created February 5, 2018 04:31
Allow 5 users login using same account
add_filter( 'authenticate',function($user, $username, $password ) {
if(isset($user->allcaps['edit_posts']) && $user->allcaps['edit_posts']){
return $user;
}
$sessions = WP_Session_Tokens::get_instance( $user->ID );
$all_sessions = $sessions->get_all();
if ( count($all_sessions) >= 5 ) {
$flag=0;
$previous_login = get_user_meta($user->ID,'last_activity',true);
@MrVibe
MrVibe / functions.php
Last active January 30, 2018 06:26
Assignment completion check in Courses
add_filter('wplms_finish_course_check',function($flag,$course_curriculum){
$user_id = get_current_user_id();
global $post;
if($post->post_type != 'course'){return $flag;}
$course_id = $post->ID;
global $wpdb;
$members_assignment_marks = $wpdb->get_results( $wpdb->prepare("SELECT meta_value as marks,post_id as assignment_id FROM {$wpdb->postmeta} where meta_key=%d AND post_id IN (SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='vibe_assignment_course' AND meta_value = %d)",$user_id,$course_id), ARRAY_A);
if(isset($members_assignment_marks) && is_array($members_assignment_marks) && count($members_assignment_marks)){
@MrVibe
MrVibe / delete_users.php
Created July 29, 2017 08:15
Delete users from WPLMS Site which logged in more than 3 months ago. Copy and past this code in Child theme - functions.php
//Screenshot of how this works : http://prntscr.com/g1qkzf
add_action('in_admin_footer',function(){
if(isset($_POST['delete_3_month_users']) && wp_verify_nonce($_POST['delete_3_month'],'delete_3_month') && current_user_can('manage_options')){
global $wpdb;
$results = $wpdb->get_results("SELECT user_id FROM {$wpdb->usermeta} WHERE `meta_key` = 'last_activity' and `meta_value` <= DATE_SUB(NOW(), INTERVAL 3 MONTH)"); // change interval to change duration.
if(is_array($results)){
echo '<div style="padding:15px;background:#fff;border:1px solid #eee;margin:15px 0;"><ol>';
if(count($results)){foreach($results as $result){
@MrVibe
MrVibe / ping_test.php
Created April 13, 2017 13:21
Ping Test from Server to another Server/Host/Ip address
<h1>Ping test from vibethemes server</h1>
<?php
$host = $_GET['host'];
if(empty($host)){die();}
if(strlen($host) > 50){die();}
set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) {
if (0 === error_reporting()) {
return false;
}
@MrVibe
MrVibe / onecourse.css
Created March 27, 2017 15:04
CSS code for One Course page theme
.homethreesteps{position:relative;padding:60px 0 0 55px;font-size:13px}.homethreesteps h4{font-size:16px;font-weight:600;margin:0 0 10px;padding:0}.homethreesteps i{font-size:28px;color:#2299dc;position:absolute;left:0;top:75px}.stripe.homesixsections{margin-top:-10px;box-shadow:0 -1px 0 rgba(0,0,0,0.1);text-align:center;padding:60px 0;background:#f3f3f3;display:inline-block;width:100%}.homesixsections h2{font-size:32px;font-weight:600;margin:0 0 20px}.homesixsections h2+p{font-size:16px;color:#666}.homesixsections .column_content{padding:30px;font-size:13px}.homesixsections .column_content i{font-size:36px}.homesixsections .column_content h4{font-size:18px;font-weight:600;margin:0 0 10px}.home header + section#content{padding-top:0}.parallaxhome{padding-bottom:0 !important}.parallaxhome .parallax_content{padding:120px 0 60px;top:20vh}.parallaxhome h2{font-size:8em;line-height:1;font-weight:800;color:#fff;text-shadow:0 0 12px #444;padding:60px 0 0}.parallaxhome h3{font-size:3em;font-weight:800;color:#fff;text
@MrVibe
MrVibe / functions.php
Created March 27, 2017 11:51
Relabel "Home" in Course Menu in WPLMS
<?php
//Copy code from here
add_filter('wplms_course_nav_menu',function($menu){ foreach($menu as $key => $item){if($item['id'] == 'home'){$menu[$key]['label']= 'MY Home';} } return $menu;});
//Till here
@MrVibe
MrVibe / functions.php
Last active March 20, 2017 07:32
WPLMS Copy existing products to courses and connect products with courses
<?php
//Copy Code from here
add_action('init',function(){
$var = get_option('wplms_products_imported_example');
if(!empty($var))
return;