Last active
January 22, 2021 10:26
-
-
Save shubham-99fusion/a314511bde92190c8278f25323afdc91 to your computer and use it in GitHub Desktop.
course and forums are connected then course author,reply author and topic author can see private replies.
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 who are topic author / reply author / course course | |
// can see course forum's topic's private reply | |
add_filter( 'bbp_get_reply_content', function($content='',$reply_id=0){ | |
$bbp_private_replies = $GLOBALS['bbp_private_replies']; | |
if( empty( $reply_id ) ) | |
$reply_id = bbp_get_reply_id( $reply_id ); | |
$content = get_post_field('post_content', $reply_id); | |
if( $bbp_private_replies->is_private( $reply_id ) ) { | |
$can_view = false; | |
$current_user = is_user_logged_in() ? wp_get_current_user() : false; | |
$topic_author = bbp_get_topic_author_id(); | |
$reply_author = bbp_get_reply_author_id( $reply_id ); | |
if ( ! empty( $current_user ) && $topic_author === $current_user->ID && user_can( $reply_author, $bbp_private_replies->capability ) ) { | |
// Let the thread author view replies if the reply author is from a moderator | |
$can_view = true; | |
} | |
if ( ! empty( $current_user ) && $reply_author === $current_user->ID ) { | |
// Let the reply author view their own reply | |
$can_view = true; | |
} | |
if( current_user_can( $bbp_private_replies->capability ) ) { | |
// Let moderators view all replies | |
$can_view = true; | |
} | |
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,$current_user->ID)){ | |
$vibe_forum_private_reply_view = get_post_meta($id,'vibe_forum_private_reply_view',true); | |
if($vibe_forum_private_reply_view == 'S'){ | |
$course_author = get_post_field('post_author',$id); | |
if ( ! empty( $current_user ) && $course_author === $current_user->ID ) { | |
// Let the course author view private reply | |
$can_view = true; | |
break;; | |
} | |
if ( ! empty( $current_user ) && $topic_author_id === $current_user->ID ) { | |
// Let the topic author view private reply on their topic | |
$can_view = true; | |
break;; | |
} | |
} | |
} | |
} | |
} | |
} | |
if(!$can_view){ | |
$content = __( 'This reply has been marked as private by wplms.', 'bbp_private_replies' ); | |
} | |
} | |
return $content; | |
}, 1000, 2 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment