/**
* LearnDash - Hide comments from Assignments and Essay from showing on Dashboard Activity Widget
*/
add_action( 'pre_get_comments', function ( $comment_query ) {
$current_screen = get_current_screen();
if ( $current_screen->id == 'dashboard' ) {
if ( !current_user_can( 'moderate_comments' ) ) {
$post_query_args = array(
'post_type' => array('sfwd-assignment', 'sfwd-essays'),
'post_status' => array( 'draft', 'publish', 'graded', 'not_graded' ),
'fields' => 'ids',
'nopaging' => true
);
$post_query = new WP_Query( $post_query_args );
if ( ( $post_query instanceof WP_Query ) && ( !empty( $post_query->posts ) ) ) {
$post__not_in = array();
if ( $comment_query->query_vars['post__not_in'] == '' )
$post__not_in = $post_query->posts;
else {
$post__not_in = array_merge( (array)$comment_query->query_vars['post__not_in'], $post_query->posts );
}
if ( !empty( $post__not_in ) )
$comment_query->query_vars['post__not_in'] = $post__not_in;
}
}
}
}, 100);
Copy to clipboard