Skip to content

Instantly share code, notes, and snippets.

@MrVibe
MrVibe / function.php
Created June 24, 2020 03:50
Remove Expired course status when user did not start the course and Enable course status from course start.
add_filter('wplms_expired_course_button',function($button,$course_id){
if(is_user_logged_in()){
$user_id = get_current_user_id();
$course_status = bp_course_get_user_course_status($user_id,$course_id);
if($course_status == 0){ //USer subscribed but not started
$init=WPLMS_tips::init();
if(!empty($init->lms_settings['calculate_course_duration_from_start_course'])){
$expiry = bp_course_get_user_expiry_time($user_id,$course_id);
@MrVibe
MrVibe / function.php
Created June 24, 2020 03:50
Remove Expired course status when user did not start the course and Enable course status from course start.
add_filter('wplms_expired_course_button',function($button,$course_id){
if(is_user_logged_in()){
$user_id = get_current_user_id();
$course_status = bp_course_get_user_course_status($user_id,$course_id);
if($course_status == 0){ //USer subscribed but not started
$init=WPLMS_tips::init();
if(!empty($init->lms_settings['calculate_course_duration_from_start_course'])){
$expiry = bp_course_get_user_expiry_time($user_id,$course_id);
@MrVibe
MrVibe / functions.php
Created June 23, 2020 06:36
Load courses only from a cateogry XX in the mobile app.
add_action('rest_api_init',function(){
add_filter('bp_course_wplms_filters',function($args){
if(empty($args['tax_query'])){
$args['tax_query']=array(
'relation' => 'AND',
array(
'taxonomy'=>'course-cat',
'field'=>'id',
'terms' =>array('xx','xx')
)
@MrVibe
MrVibe / functions.php
Created June 13, 2020 13:04
Paid Custom Registration form, lets say product id XX
add_filter('wplms_registration_form_submit_button',function($return){
if(is_user_logged_in()){
$check = wc_customer_bought_product('',get_current_user_id(),XX);
if($check){
return $return;
}
}
return '<a href="'.get_permalink(XX).'">Purchase Membership $99</a>';
@MrVibe
MrVibe / functions.php
Created June 6, 2020 02:00
Send email to administrator when user registers form custom registration form
add_action('wplms_custom_registration_form_user_added',function($user_id,$user_args,$settings){
$admins = get_users('role=Administrator');
$admin_emails = []; //PHP 7.2+ else change to $admin_Emails = array();
foreach ($blogusers as $user) {
$admin_emails[]=$user->user_email;
}
$admin_emails = implode(',',$admin_emails);
$subject = 'User registered in site';
$body = 'The user '.$user_args['user_email'].' registered in your site';
@MrVibe
MrVibe / functions.php
Created May 22, 2020 04:39
Add groundhogg tag
add_action( 'wplms_submit_course', 'add_a_tag_when_complete_course', 10, 2 );
function add_a_tag_when_complete_course( $course_id, $user_id )
{
if($course_id !== 1500)
return;
$tags_to_add = [ 'Course1Complete', 'Course2Prospect' ];
$contact = \Groundhogg\Plugin::$instance->tracking->get_current_contact();
if ( ! $contact ){
return;
@MrVibe
MrVibe / functions.php
Last active May 6, 2020 04:31
Disable course retakes once the user passes the course and gets course certificate
add_filter('wplms_course_retake_count',function($count,$course_id,$user_id){
$status = bp_course_get_user_course_status($user_id,$course_id);
if($status == 4){
$marks = bp_course_get_marks($user_id,$course_id);
$passing_per = get_post_meta($id,'vibe_course_passing_percentage',true);
if($marks > $passing_per){
return 0;
}
}
@MrVibe
MrVibe / functions.php
Last active May 22, 2020 15:11
Load different Unit content from Meta in API
//video so app
add_filter('wplms_unit_metabox',function($box){
$box[]=array( // Single checkbox
'label' => __('Unit Content for App','vibe-customtypes'), // <label>
'desc' => __('Unit Content for App.','vibe-customtypes'), // description
'id' => 'vibe_app_content', // field id and name
'type' => 'editor', // type of field
'std' => ''
);
return $box;
@MrVibe
MrVibe / functions.php
Created April 7, 2020 08:53
Ajax add to cart in WPLMS
add_action('wp_footer',function(){
if(is_singular('course')){
?><script>
jQuery(document).ready(function($){
if($('.course_button').attr('href').indexOf('?redirect')){
$('.course_button').on('click',function(e){
e.preventDefault();
$.ajax({
type: "POST",
@MrVibe
MrVibe / functions.php
Created April 2, 2020 04:27
singleItem with course button & details
add_filter('bp_course_single_item_view',function($flag){
global $post;
$course_post_id = $post->ID;
$course_author= $post->post_author;
$course_classes = apply_filters('bp_course_single_item','course_single_item course_id_'.$post->ID.' course_status_'.$post->post_status.' course_author_'.$post->post_author,get_the_ID());
?>
<li class="<?php echo $course_classes; ?>">
<div class="row">
<div class="col-md-4">