Skip to content

Instantly share code, notes, and snippets.

@MrVibe
MrVibe / functions.php
Created April 8, 2021 09:52
Restrict Unit types per member
add_filter('wplms_course_creation_tabs',function($tabs,$user_id){
//USER_ID , get Instructor Type
if(CONDITION FOR INSTRUCTOR MEMBER TYPE DETECTION) {
$unit_types = $tabs['course_curriculum']['fields'][0]['curriculum_elements'][1]['types'];
foreach($unit_types as $k=>$type){
if($type['id'] == 'video'){ //Match Unit Type
unset($unit_types[$k]); // Unset for Instructor
}
}
@MrVibe
MrVibe / functions.php
Created March 11, 2021 23:48
Appointments Cart click not redirecting to cart. Paste in WP Admin - WPLMS - Footer - Analytics code.
<script>
document.addEventListener('appointmentSlotAdded',function(){
var el = document.querySelector('.vbpcart'),
elClone = el.cloneNode(true);
el.parentNode.replaceChild(elClone, el);
});
</script>
@MrVibe
MrVibe / functions.php
Last active March 16, 2021 08:01
Direct checkout other themes
add_filter('wplms_course_non_loggedin_user',function($link){
$link = str_replace('">','?redirect">',$link);
return $link;
});
add_action( 'template_redirect', function(){
if( is_single() && get_post_type() == 'product' && isset($_GET['redirect'])){
global $woocommerce;
$found = false;
$product_id = get_the_ID();
$courses = vibe_sanitize(get_post_meta(get_the_ID(),'vibe_courses',false));
@MrVibe
MrVibe / functions.php
Last active February 19, 2021 06:40
Unit timings print on certificate
add_shortcode('certificate_course_unit_timings',function($atts,$content=null){
$return = '';
$course_id = ;
$user_id = ;
$course_curriculum = bp_course_get_curriculum( $course_id );
$unit_timing = array();
$init = WPLMS_Unit_Timings_Init::Instance_WPLMS_Unit_Timings_Init();
@MrVibe
MrVibe / functions.php
Created January 14, 2021 10:07
Add custom icon for component in vibebp
add_filter('vibebp_component_icon'function($icon,$compoent({
if($id == 'wishlist'){ // Check component id , set $icon as svg
$icon = '<svg width="24" height="24" viewBox="0 0 24 24" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
<path d="M15.473,19.593C14.365,20.679 13.198,21.812 12,23C5.57,16.619 0,11.853 0,7.192C0,0.423 8.852,-1.154 12,4.248C15.125,-1.114 24,0.4 24,7.192C24,7.938 23.844,8.688 23.577,9.445C22.461,8.543 21.043,8 19.5,8C15.916,8 13,10.916 13,14.5C13,16.563 13.97,18.401 15.473,19.593Z" style="fill-opacity:0.6;fill-rule:nonzero;"/>
<path d="M19.5,10C17.017,10 15,12.015 15,14.5C15,16.985 17.017,19 19.5,19C21.983,19 24,16.985 24,14.5C24,12.015 21.983,10 19.5,10ZM22,15L20,15L20,17L19,17L19,15L17,15L17,14L19,14L19,12L20,12L20,14L22,14L22,15Z" style="fill-rule:nonzero;"/></svg>';
}
return $icon;
},10,2);
@MrVibe
MrVibe / functions.php
Created January 13, 2021 06:27
Youtube Preview video in profile. Field ID 51 , add this in WP Admin - WPLMS - footer - google analytics code
<script>
if(document.querySelector('.vibebp_profile_field.field_51')){
new Promise(function(resolve){
let youtube_url = document.querySelector('.vibebp_profile_field.field_51 > div').textContent;
let ycode = youtube_url.match(/v=([^&#]{5,})/);
var mdiv = document.createElement('div');
mdiv.setAttribute('id','field_51_youtube');
mdiv.setAttribute('data-plyr-provider','youtube');
mdiv.setAttribute('data-plyr-embed-id',ycode[1]);
@MrVibe
MrVibe / functions.php
Created January 8, 2021 16:15
Direct checkout in WooCommerce for non-WPLMS theme.
add_action( 'template_redirect', 'vibe_product_woocommerce_direct_checkout');
function vibe_product_woocommerce_direct_checkout(){
if(in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))) || (function_exists('vibe_check_plugin_installed') && vibe_check_plugin_installed( 'woocommerce/woocommerce.php')) || function_exists('WC')){
if( is_single() && get_post_type() == 'product' && isset($_GET['redirect'])){
global $woocommerce;
$found = false;
$product_id = get_the_ID();
$courses = vibe_sanitize(get_post_meta(get_the_ID(),'vibe_courses',false));
@MrVibe
MrVibe / functions.php
Last active December 20, 2020 07:14
Private replies visible to course members. vibe-helpdesk
add_filter('bbp_reply_is_private',function($return,$reply_id){
$api = Vibe_HelpDesk_API::init();
if(!empty($api->user)){
$forum_id = get_post_meta($reply_id,'_bbp_forum_id',true);
global $wpdb;
$course_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='vibe_forum' AND meta_value = %d",$forum_id));
if(!empty($course_id)){
if(bp_course_is_member($course_id,$api->user->id)){
return false;
}
@MrVibe
MrVibe / functions.php
Created November 29, 2020 14:25
Capture Batch details for Certificate
add_shortcode('certificate_batch_details',function($atts,$content=null){
extract(shortcode_atts(array(
'student_id' => '',
'course_id' =>'',
'detail'=>'0' //name, administartor,
), $atts));
if(!isset($course_id) || !is_numeric($course_id)){
$course_id=$_GET['c'];
}
add_filter('wplms_get_featured_cards',function($cards){
$cards['custom_block']='CUSTOM BLOCK';
return $cards;
});