Last active
April 6, 2021 07:29
-
-
Save shubham-99fusion/88db8e3bd16d2dd15ed8fd7a1a02a2b7 to your computer and use it in GitHub Desktop.
Course user see the private replies(update)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(!empty($GLOBALS['bbp_private_replies'])){ | |
//settings in course settings page | |
add_filter('wplms_course_creation_tabs','add_in_front_end'); | |
function add_in_front_end($settings){ | |
$fields = $settings['course_settings']['fields']; | |
$arr=array(array( | |
'label' => __('Course Students can see forum private reply','wplms-front-end'), // <label> | |
'desc' => __('Course Students can see forum private reply','wplms-front-end'), | |
'text'=>__('Forum private reply','wplms-front-end' ),// description | |
'id' => 'vibe_forum_private_reply_view', // field id and name | |
'type'=> 'switch', | |
'default'=>'H', | |
'options' => array('H'=>__('disable','wplms' ),'S'=>__('enable','wplms' )), | |
'style'=>'', | |
'from' => 'meta' | |
)); | |
array_splice($fields, (count($fields)-1), 0,$arr ); | |
$settings['course_settings']['fields'] = $fields; | |
return $settings; | |
} | |
//Check for private if course forum setting enabled then course users can see course forum's any topic's | |
//private reply | |
add_filter('user_can_view_private_replies',function($can_view,$reply_id,$user_id){ | |
if( ! $can_view ) { | |
$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)); | |
$course_ids = array(); | |
if(!empty($course_id) && !is_array($course_id)){ | |
$course_ids = (array)$course_id; | |
}else if(!empty($course_id) && is_array($course_id)){ | |
$course_ids = $course_id; | |
} | |
if(!empty($course_ids) && is_array($course_ids)){ | |
$topic_id= bbp_get_reply_topic_id($reply_id); | |
$topic_author_id = bbp_get_topic_author_id( $topic_id ); | |
foreach ($course_ids as $key => $id) { | |
if(bp_course_is_member($id,$user_id)){ | |
$vibe_forum_private_reply_view = get_post_meta($id,'vibe_forum_private_reply_view',true); | |
if($vibe_forum_private_reply_view == 'S'){ | |
$can_view = true; | |
break; | |
} | |
} | |
} | |
} | |
} | |
return $can_view; | |
},10,3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment