function bp_course_add_user_to_course($user_id, $course_id) { $duration = get_post_meta($course_id, 'vibe_duration', true); $course_duration_parameter = apply_filters('vibe_course_duration_parameter', 86400); $t = time() + $duration * $course_duration_parameter; update_post_meta($course_id, $user_id, 0); update_user_meta($user_id, 'course_status' . $course_id, 1); update_user_meta($user_id, $course_id, $t); $group_id = get_post_meta($course_id, 'vibe_group', true); if (isset($group_id) && $group_id != '') { groups_join_group($group_id, $user_id); } bp_course_record_activity(array('action' => __('Student subscribed for course ', 'vibe') . get_the_title($course_id), 'content' => __('Student ', 'vibe') . bp_core_get_userlink($user_id) . __(' subscribed for course ', 'vibe') . get_the_title($course_id) . __(' for ', 'vibe') . $duration . __(' days', 'vibe'), 'type' => 'subscribe_course', 'item_id' => $course_id, 'primary_link' => get_permalink($course_id), 'secondary_item_id' => $user_id)); }
function wplms_course_code_check() { $user_id = get_current_user_id(); $course_id = get_the_ID(); $course_codes = get_post_meta($course_id, 'vibe_course_codes', true); if ($_POST['submit_course_codes']) { if (!isset($_POST['security_code']) || !wp_verify_nonce($_POST['security_code'], 'security' . $user_id)) { echo '<p class="message">' . __('Security check Failed. Contact Administrator.', 'vibe-customtypes') . '</p>'; } else { $code = $_POST['course_code']; if (isset($code) && strlen($code) < 2) { echo '<p class="message">' . __('Code does not exist. Please check the code.', 'vibe-customtypes') . '</p>'; return; } $x = preg_match("/(^|,){$code}(\\|([0-9]+)|(,|\$))/", $course_codes, $matches); if (!$x) { echo '<p class="message">' . __('Code does not exist. Please check the code.', 'vibe-customtypes') . '</p>'; return; } else { global $wpdb, $bp; if (isset($matches[3]) && is_numeric($matches[3])) { $total_count = $matches[3]; $count = $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM {$bp->activity->table_name} WHERE component = %s AND type = %s AND content = %s AND item_id = %d", 'course', 'course_code', $code, $course_id)); if ($count <= $total_count) { if (!wplms_user_course_check($user_id, $course_id)) { bp_course_record_activity(array('action' => __('Course code applied', 'vibe-customtypes'), 'content' => $code, 'type' => 'course_code', 'item_id' => $course_id, 'primary_link' => get_permalink($course_id), 'secondary_item_id' => $user_id)); do_action('wplms_course_code', $code, $course_id, $user_id); bp_course_add_user_to_course($user_id, $course_id); echo '<p class="message success">' . __('Congratulations! You are now added to the course.', 'vibe-customtypes') . '</p>'; } else { echo '<p class="message">' . __('User already in course.', 'vibe-customtypes') . '</p>'; } } else { echo '<p class="message">' . __('Maximum number of usage for course code exhausted', 'vibe-customtypes') . '</p>'; } } else { if (!wplms_user_course_check($user_id, $course_id)) { do_action('wplms_course_code', $code, $course_id, $user_id); bp_course_add_user_to_course($user_id, $course_id); echo '<p class="message success">' . __('Congratulations! You are now added to the course.', 'vibe-customtypes') . '</p>'; } else { echo '<p class="message">' . __('User already in course.', 'vibe-customtypes') . '</p>'; } } } } } }
function record($args = array()) { $defaults = array('action' => 'mycred_add', 'user_id' => get_current_user_id(), 'module' => 'course', 'amount' => 0, 'logentry' => 'Started Course', 'id' => 0, 'message' => 'Student Started course'); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $mycred = mycred(); $mycred->add_to_log($action, $user_id, $amount, $logentry, $id, $message); $bp_args = array('user_id' => $user_id, 'action' => $action, 'content' => $message, 'primary_link' => get_permalink($id), 'component' => $module, 'item_id' => $id); bp_course_record_activity($bp_args); }
function unit_traverse1() { $unit_id = $_POST['id']; $course_id = $_POST['course_id']; if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'security')) { _e('Security check Failed. Contact Administrator.', 'vibe'); die; } // Check if user has taken the course $user_id = get_current_user_id(); $coursetaken = get_user_meta($user_id, $course_id, true); //if(!isset($_COOKIE['course'])) { // code cũ if($coursetaken>time()){ if ($coursetaken) { setcookie('course', $course_id, $expire, '/'); $_COOKIE['course'] = $course_id; } else { $pid = get_post_meta($course_id, 'vibe_product', true); $pid = apply_filters('wplms_course_product_id', $pid, $course_id, -1); // $id checks for Single Course page or Course page in the my courses section if (is_numeric($pid)) { $pid = get_permalink($pid); } echo '<div class="message"><p>' . __('Course Expired.', 'vibe') . '<a href="' . $pid . '" class="link alignright">' . __('Click to renew', 'vibe') . '</a></p></div>'; die; } //} if (isset($coursetaken) && $coursetaken) { $course_curriculum = vibe_sanitize(get_post_meta($course_id, 'vibe_course_curriculum', false)); $units = array(); foreach ($course_curriculum as $key => $curriculum) { if (is_numeric($curriculum)) { $units[] = $curriculum; } } // Drip Feed Check $drip_enable = get_post_meta($course_id, 'vibe_course_drip', true); if (vibe_validate($drip_enable)) { $drip_duration = get_post_meta($course_id, 'vibe_course_drip_duration', true); $unitkey = array_search($unit_id, $units); if ($unitkey == 0) { $pre_unit_time = get_post_meta($units[$unitkey], $user_id, true); if (!isset($pre_unit_time) || $pre_unit_time == '') { add_post_meta($units[$unitkey], $user_id, time()); } } else { $pre_unit_time = get_post_meta($units[$unitkey - 1], $user_id, true); if (isset($pre_unit_time) && $pre_unit_time) { $drip_duration_parameter = apply_filters('vibe_drip_duration_parameter', 86400); $value = $pre_unit_time + $drip_duration * $drip_duration_parameter; $value = apply_filters('wplms_drip_value', $value, $units[$unitkey - 1], $course_id); if ($value > time()) { echo '<div class="message"><p>' . __('Unit will be available in ', 'vibe') . tofriendlytime($pre_unit_time + $drip_duration * $drip_duration_parameter - time()) . '</p></div>'; die; } else { $pre_unit_time = get_post_meta($units[$unitkey], $user_id, true); if (!isset($pre_unit_time) || $pre_unit_time == '') { add_post_meta($units[$unitkey], $user_id, time()); bp_course_record_activity(array('action' => __('Student started a unit', 'vibe'), 'content' => __('Student started the unit ', 'vibe') . get_the_title($unit_id) . __(' in course ', 'vibe') . get_the_title($course_id), 'type' => 'unit', 'primary_link' => get_permalink($unit_id), 'item_id' => $unit_id, 'secondary_item_id' => $user_id)); } } } else { echo '<div class="message"><p>' . __('Unit can not be accessed.', 'vibe') . '</p></div>'; die; } } } // END Drip Feed Check echo '<div class="tabheader" style="width:77.7%;"> <span class="title_unit" >' . get_the_title($unit_id) . '</span> </div>'; $typequiz = get_post_type($unit_id); if ($typequiz == "quiz") { do_action('wplms_unit_header', $unit_id, $course_id); } echo '<div id="unit" class="quiz_title" data-unit="' . $unit_id . '">'; the_unit_tags($unit_id); the_unit_instructor($unit_id); $minutes = 0; $mins = get_post_meta($unit_id, 'vibe_duration', true); $unit_duration_parameter = apply_filters('vibe_unit_duration_parameter', 60); if ($mins) { if ($mins > $unit_duration_parameter) { $hours = floor($mins / $unit_duration_parameter); $minutes = $mins - $hours * $unit_duration_parameter; } else { $minutes = $mins; } do_action('wplms_course_unit_meta'); if ($mins < 9999) { if ($unit_duration_parameter == 1) { echo '<span><i class="icon-clock"></i> ' . (isset($hours) ? $hours . __(' Minutes', 'vibe') : '') . ' ' . $minutes . __(' seconds', 'vibe') . '</span>'; } else { if ($unit_duration_parameter == 60) { echo '<span><i class="icon-clock"></i> ' . (isset($hours) ? $hours . __(' Hours', 'vibe') : '') . ' ' . $minutes . __(' minutes', 'vibe') . '</span>'; } else { if ($unit_duration_parameter == 3600) { echo '<span><i class="icon-clock"></i> ' . (isset($hours) ? $hours . __(' Days', 'vibe') : '') . ' ' . $minutes . __(' hours', 'vibe') . '</span>'; } } } } } echo '<div class="clear"></div>'; echo '<h1>' . get_the_title($unit_id) . '</h1>'; echo '<h3>'; the_sub_title($unit_id); echo '</h3></div>'; the_unit($unit_id); $unit_class = 'unit_button'; $hide_unit = 0; $nextunit_access = vibe_get_option('nextunit_access'); $k = array_search($unit_id, $units); $done_flag = get_user_meta($user_id, $unit_id, true); $next = $k + 1; $prev = $k - 1; $max = count($units) - 1; echo '<div class="unit_prevnext">'; echo '<div class="col-md-2"> <span class="backtocourse" data-id="' . $course_id . '"><i class="icon-arrow-1-left"></i> Trở về khóa học </span></div>'; echo '<div class="col-md-2">'; if ($prev >= 0) { if (get_post_type($units[$prev]) == 'quiz') { $quiz_status = get_user_meta($user_id, $units[$prev], true); if (!empty($quiz_status)) { echo '<a href="#" data-unit="' . $units[$prev] . '" class="' . $unit_class . '">' . __('Back to Quiz', 'vibe') . '</a>'; } else { echo '<a href="' . get_permalink($units[$prev]) . '" class="unit_button">' . __('Back to Quiz', 'vibe') . '</a>'; } } else { echo '<a href="#" id="prev_unit" data-unit="' . $units[$prev] . '" class="unit unit_button">' . __('Previous Unit', 'vibe') . '</a>'; } } echo '</div>'; echo '<div class="col-md-2">'; if ($next <= $max) { if (isset($nextunit_access) && $nextunit_access) { $hide_unit = 1; if (isset($done_flag) && $done_flag) { $unit_class .= ' '; $hide_unit = 0; } else { $unit_class .= ' hide'; $hide_unit = 1; } } if (get_post_type($units[$next]) == 'quiz') { $quiz_status = get_user_meta($user_id, $units[$next], true); if (!empty($quiz_status)) { echo '<a href="#" data-unit="' . $units[$next] . '" class="unit ' . $unit_class . '">' . __('Proceed to Quiz', 'vibe') . '</a>'; } else { // echo '<a href="'.get_permalink($units[$next]).'" class=" unit_button">'.__('Proceed to Quiz','vibe').'</a>'; echo '<a href="#" data-unit="' . $units[$next] . '" class="unit ' . $unit_class . '">' . __('Proceed to Quiz', 'vibe') . '</a>'; } } else { echo '<a href="#" id="next_unit" ' . ($hide_unit ? '' : 'data-unit="' . $units[$next] . '"') . ' class="unit ' . $unit_class . '">' . __('Next Unit', 'vibe') . '</a>'; } } echo '</div>'; echo '<div class="col-md-4" style="text-align: center">'; if (get_post_type($units[$k]) == 'quiz') { $quiz_status = get_user_meta($user_id, $units[$k], true); // if(!empty($quiz_status)){ // echo '<a href="'.bp_loggedin_user_domain().BP_COURSE_SLUG.'/'.BP_COURSE_RESULTS_SLUG.'/?action='.$units[($k)].'" class="quiz_results_popup">'.__('Check Results','vibe').'</a>'; // }else{ // echo '<a href="'.get_permalink($units[($k)]).'" class=" unit_button start_quiz">'.__('Start Quiz','vibe').'</a>'; // } if (is_numeric($quiz_status)) { if ($quiz_status < time()) { echo '<script>document.getElementsByClassName("quiz_meta")[0].style.display = "none"</script>'; echo '<a href="' . bp_loggedin_user_domain() . BP_COURSE_SLUG . '/' . BP_COURSE_RESULTS_SLUG . '/?action=' . $units[$k] . '" class="quiz_results_popup">' . __('Check Results', 'vibe') . '</a>'; } else { $quiz_class = apply_filters('wplms_in_course_quiz', ''); echo '<a href="' . get_permalink($units[$k]) . '" class=" unit_button ' . $quiz_class . ' continue">' . __('Continue Quiz', 'vibe') . '</a>'; } } else { $quiz_class = apply_filters('wplms_in_course_quiz', ''); echo '<a href="' . get_permalink($units[$k]) . '" class=" unit_button ' . $quiz_class . '">' . __('Start Quiz', 'vibe') . '</a>'; } } else { echo isset($done_flag) && $done_flag ? '' : apply_filters('wplms_unit_mark_complete', '<a href="#" id="mark-complete" data-unit="' . $units[$k] . '" class="unit_button">' . __('Mark this Unit Complete', 'vibe') . '</a>', $unit_id, $course_id); } echo '</div>'; echo '<div class="col-md-2">'; echo '<span class="auto_complete" data-id="false"> </span>'; echo '</div>'; echo '</div></div>'; } die; }
function wplms_check_course_retake() { if (!isset($_POST['security'])) { return; } $user_id = get_current_user_id(); if (!wp_verify_nonce($_POST['security'], 'retake' . $user_id)) { echo '<p class="error">' . __('Security check failed !', 'vibe') . '</p>'; return; } $course_id = get_the_ID(); $status = bp_course_get_user_course_status($user_id, $course_id); if (isset($status) && is_numeric($status)) { // Necessary for continue course do_action('wplms_student_course_reset', $course_id, $user_id); bp_course_update_user_course_status($user_id, $course_id, 0); // New function $course_curriculum = vibe_sanitize(get_post_meta($course_id, 'vibe_course_curriculum', false)); foreach ($course_curriculum as $c) { if (is_numeric($c)) { delete_user_meta($user_id, $c); delete_post_meta($c, $user_id); if (get_post_type($c) == 'quiz') { $questions = vibe_sanitize(get_post_meta($c, 'quiz_questions' . $user_id, false)); if (!isset($questions) || !is_array($questions)) { // Fallback for Older versions $questions = vibe_sanitize(get_post_meta($c, 'vibe_quiz_questions', false)); } else { delete_post_meta($c, 'quiz_questions' . $user_id); } // Re-capture new questions in quiz begining if (isset($questions) && is_array($questions) && is_Array($questions['ques'])) { foreach ($questions['ques'] as $question) { global $wpdb; if (isset($question) && $question != '' && is_numeric($question)) { $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved='trash' WHERE comment_post_ID=%d AND user_id=%d", $question, $user_id)); } } } } } } $user_badges = vibe_sanitize(get_user_meta($user_id, 'badges', false)); $user_certifications = vibe_sanitize(get_user_meta($user_id, 'certificates', false)); if (isset($user_badges) && is_Array($user_badges) && in_array($course_id, $user_badges)) { $key = array_search($course_id, $user_badges); unset($user_badges[$key]); $user_badges = array_values($user_badges); update_user_meta($user_id, 'badges', $user_badges); } if (isset($user_certifications) && is_Array($user_certifications) && in_array($course_id, $user_certifications)) { $key = array_search($course_id, $user_certifications); unset($user_certifications[$key]); $user_certifications = array_values($user_certifications); update_user_meta($user_id, 'certificates', $user_certifications); } /*==== End Fix ======*/ bp_course_record_activity(array('action' => __('Student retake Course ', 'vibe'), 'content' => __('Course ', 'vibe') . get_the_title($course_id) . __(' retake by student ', 'vibe') . bp_core_get_userlink($user_id), 'type' => 'retake_course', 'primary_link' => get_permalink($course_id), 'item_id' => $course_id, 'secondary_item_id' => $user_id)); echo "<script>jQuery(document).ready(function(\$){ \$.removeCookie('course_progress{$course_id}', { path: '/' });</script>"; } else { echo '<p class="error">' . __('There was issue in retaking this course for the user. Please contact admin.', 'vibe') . '</p>'; } }
function articulate_payload($record, $referer) { $user_id = get_current_user_id(); $object = $this->parse_xml($record['object'], $referer); $course = $this->parse_xml($record['courseid'], $referer); bp_course_record_activity(array('action' => __('Student ', 'vibe') . $record['verb'] . ' ' . $object, 'content' => __('Student ', 'vibe') . bp_core_get_userlink($user_id) . ' ' . $record['verb'] . ' ' . $object . __(' in ', 'vibe') . $course, 'type' => $record['verb'], 'item_id' => $record['courseid'], 'primary_link' => $referer)); }
function wplms_event_accept_reject_invitation() { if (!isset($_GET['security'])) { return; } $security = $_GET['security']; $event_id = get_the_ID(); $user_id = get_current_user_id(); if (!isset($security)) { //|| !wp_verify_nonce($security,'vibe_'.$event_id.$user_id )//Validate NONCE echo '<div class="error">'; _e('Security check Failed. Contact Administrator.', 'wplms-events'); echo '</div>'; return; } if (isset($_GET['accept'])) { if (update_post_meta($event_id, $user_id, 1)) { echo '<div class="success">'; _e('Invitation accepted.', 'wplms-events'); echo '</div>'; do_action('wplms_event_invitation_accepted'); } else { echo '<div class="error">'; _e('Unable to accept invitation.', 'wplms-events'); echo '</div>'; } bp_course_record_activity(array('action' => __('Student Accepted Event Invitation ', 'wplms-events') . get_the_title($event_id), 'content' => __('Student ', 'wplms-events') . bp_core_get_userlink($user_id) . __(' accepted invitation for Event ', 'wplms-events') . get_the_title($event_id), 'type' => 'invitation_response', 'primary_link' => get_permalink($event_id), 'item_id' => $event_id, 'secondary_item_id' => $user_id)); } if (isset($_GET['reject'])) { if (update_post_meta($event_id, $user_id, 2)) { echo '<div class="success">'; _e('Invitation rejected.', 'wplms-events'); echo '</div>'; do_action('wplms_event_invitation_rejected'); bp_course_record_activity(array('action' => __('Student Rejected Event Invitation ', 'wplms-events') . get_the_title($event_id), 'content' => __('Student ', 'wplms-events') . bp_core_get_userlink($user_id) . __(' accepted invitation for Event ', 'wplms-events') . get_the_title($event_id), 'type' => 'invitation_response', 'primary_link' => get_permalink($event_id), 'item_id' => $event_id, 'secondary_item_id' => $user_id)); } else { echo '<div class="error">'; _e('Unable to reject invitation.', 'wplms-events'); echo '</div>'; } } }
function reset_assignment($assignment_id, $user_id) { bp_course_record_activity(array('action' => __('Instructor Reseted the Assignment for User', 'vibe'), 'content' => sprintf(__('Assignment %s was reset by the Instructor for user %s', 'vibe'), get_the_title($assignment_id), bp_core_get_userlink($user_id)), 'type' => 'reset_assignment', 'primary_link' => get_permalink($assignment_id), 'item_id' => $assignment_id, 'secondary_item_id' => $user_id)); }
function bp_activity_course_update($object, $item_id, $content) { global $bp; $activity_id = bp_course_record_activity(array('action' => sprintf(__('%s posted an update in the course %s', 'vibe'), bp_core_get_userlink($bp->loggedin_user->id), '<a href="' . get_permalink($item_id) . '">' . get_the_title($item_id) . '</a>'), 'content' => $content, 'primary_link' => get_permalink($item_id), 'item_id' => $item_id, 'type' => $object)); return $activity_id; }
function wplms_edd_completed_purchase($payment_id, $new_status, $old_status) { if ($old_status == 'publish' || $old_status == 'complete') { return; } // Make sure that payments are only completed once // Make sure the payment completion is only processed when new status is complete if ($new_status != 'publish' && $new_status != 'complete') { return; } $user_id = get_current_user_id(); $cart_items = edd_get_payment_meta_cart_details($payment_id); foreach ($cart_items as $key => $cart_item) { $item_id = isset($cart_item['id']) ? $cart_item['id'] : $cart_item; if (is_numeric($item_id) && get_post_type($item_id) == 'download') { $courses = vibe_sanitize(get_post_meta($item_id, 'vibe_courses', false)); $subscribed = get_post_meta($product_id, 'vibe_subscription', true); if (vibe_validate($subscribed)) { $duration = get_post_meta($product_id, 'vibe_duration', true); $product_duration_parameter = apply_filters('vibe_product_duration_parameter', 86400); // Product duration for subscription based $t = time() + $duration * $product_duration_parameter; foreach ($courses as $course) { update_post_meta($course, $user_id, 0); update_user_meta($user_id, $course, $t); $group_id = get_post_meta($course, 'vibe_group', true); if (isset($group_id) && $group_id != '') { groups_join_group($group_id, $user_id); } bp_course_record_activity(array('action' => __('Student subscribed for course ', 'vibe') . get_the_title($course), 'content' => __('Student ', 'vibe') . bp_core_get_userlink($user_id) . __(' subscribed for course ', 'vibe') . get_the_title($course) . __(' for ', 'vibe') . $duration . __(' days', 'vibe'), 'type' => 'subscribe_course', 'item_id' => $course, 'primary_link' => get_permalink($course), 'secondary_item_id' => $user_id)); } } else { if (isset($courses) && is_array($courses)) { foreach ($courses as $course) { $duration = get_post_meta($course, 'vibe_duration', true); $course_duration_parameter = apply_filters('vibe_course_duration_parameter', 86400); // Course duration for subscription based $t = time() + $duration * $course_duration_parameter; update_post_meta($course, $user_id, 0); update_user_meta($user_id, $course, $t); $group_id = get_post_meta($course, 'vibe_group', true); if (isset($group_id) && $group_id != '') { groups_join_group($group_id, $user_id); } bp_course_record_activity(array('action' => __('Student subscribed for course ', 'vibe') . get_the_title($course), 'content' => __('Student ', 'vibe') . bp_core_get_userlink($user_id) . __(' subscribed for course ', 'vibe') . get_the_title($course) . __(' for ', 'vibe') . $duration . __(' days', 'vibe'), 'type' => 'subscribe_course', 'item_id' => $course, 'primary_link' => get_permalink($course), 'secondary_item_id' => $user_id)); } } } } } }
function course_go_live($course_id, $the_post) { if ($the_post['post_status'] == 'publish') { bp_course_record_activity(array('action' => sprintf(__('Instructor Published the course Course %s ', 'vibe'), $the_post['post_title']), 'content' => sprintf(__('Instructor %s published the Course %s ', 'vibe'), bp_core_get_userlink($the_post['post_author']), $the_post['post_title']), 'type' => 'course_published', 'item_id' => $course_id, 'primary_link' => get_permalink($course_id), 'secondary_item_id' => $the_post['post_author'])); } else { bp_course_record_activity(array('action' => sprintf(__('Instructor submitted the Course %s for approval', 'vibe'), $the_post['post_title']), 'content' => sprintf(__('Instructor %s submitted the Course %s for approval', 'vibe'), bp_core_get_userlink($the_post['post_author']), $the_post['post_title']), 'type' => 'course_approval', 'item_id' => $course_id, 'primary_link' => get_permalink($course_id), 'secondary_item_id' => $the_post['post_author'])); } }
function use_mycred_points() { $user_id = get_current_user_id(); $course_id = $_POST['id']; if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'security' . $user_id)) { _e('Security check Failed.', 'wplms-mycred'); die; } if (!is_numeric($course_id) || get_post_type($course_id) != 'course') { _e('Incorrect Course', 'wplms-mycred'); die; } $points = get_post_meta($course_id, 'vibe_mycred_points', true); $mycred = mycred(); $balance = $mycred->get_users_cred($user_id); if ($balance < $points) { _e('Not enough balance', 'wplms-mycred'); die; } $deduct = -1 * $points; $start_date = get_post_meta($course, 'vibe_start_date', true); $time = 0; if (isset($start_date) && $start_date) { $time = strtotime($start_date); } if ($time < time()) { $time = time(); } $subscription = get_post_meta($course_id, 'vibe_mycred_subscription', true); if (isset($subscription) && $subscription && $subscription != 'H') { $duration = get_post_meta($course_id, 'vibe_mycred_duration', true); if (!isset($duration) || !$duration) { _e('Please set subscription duration or disable subscription', 'wplms-mycred'); die; } $duration_parameter = $this->subscription_duration_parameter; $expiry = $time + $duration * $duration_parameter; update_user_meta($user_id, $course_id, $expiry); update_post_meta($course_id, $user_id, 0); } else { $duration = get_post_meta($course_id, 'vibe_duration', true); $duration_parameter = apply_filters('vibe_course_duration_parameter', 86400); $expiry = $time + $duration * $duration_parameter; update_user_meta($user_id, $course_id, $expiry); update_post_meta($course_id, $user_id, 0); } $mycred->update_users_balance($user_id, $deduct); $mycred->add_to_log('take_course', $user_id, $deduct, __('Student subscibed for course', 'wplms-mycred'), $course_id, __('Student Subscribed to course , ends on ', 'wplms-mycred') . date("jS F, Y", $expiry)); $durationtime = $duration . ' ' . calculate_duration_time($duration_parameter); bp_course_record_activity(array('action' => __('Student subscribed for course ', 'vibe') . get_the_title($course_id), 'content' => __('Student ', 'vibe') . bp_core_get_userlink($user_id) . __(' subscribed for course ', 'vibe') . get_the_title($course_id) . __(' for ', 'vibe') . $durationtime, 'type' => 'subscribe_course', 'item_id' => $course_id, 'primary_link' => get_permalink($course_id), 'secondary_item_id' => $user_id)); $instructors[$course] = apply_filters('wplms_course_instructors', get_post_field('post_author', $course_id), $course_id); // Commission calculation if (function_exists('vibe_get_option')) { $instructor_commission = vibe_get_option('instructor_commission'); } if ($instructor_commission == 0) { return; } if (!isset($instructor_commission) || !$instructor_commission) { $instructor_commission = 70; } $instructors[$course_id] = apply_filters('wplms_course_instructors', get_post_field('post_author', $course_id), $course_id); $commissions = get_option('instructor_commissions'); if (isset($commissions) && is_array($commissions)) { if (is_array($instructors)) { $instructors = array_unique($instructors); foreach ($instructors as $instructor) { if (isset($commissions[$course_id]) && isset($commissions[$course_id][$instructor])) { $calculated_commission_base = round($points * $commissions[$course_id][$instructor] / 100, 2); } else { $instructor_commission = $instructor_commission / count($instructors); $calculated_commission_base = round($points * $instructor_commission / 100, 2); } $mycred->add_to_log('instructor_commission', $instructor, $calculated_commission_base, __('Instructor earned commission', 'wplms-mycred'), $course_id, __('Instructor earned commission for student purchasing the course via points ', 'wplms-mycred')); } } else { if (isset($commissions[$course_id][$instructors])) { $calculated_commission_base = round($points * $commissions[$course_id][$instructors] / 100, 2); } else { $calculated_commission_base = round($points * $instructor_commission / 100, 2); } $mycred->add_to_log('instructor_commission', $instructor, $calculated_commission_base, __('Instructor earned commission', 'wplms-mycred'), $course_id, __('Instructor earned commission for student purchasing the course via points ', 'wplms-mycred')); } } // End Commissions_array do_action('wplms_course_mycred_points_puchased', $course_id, $user_id, $points); die; }