Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2020
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.00 KB | None | 0 0
  1.     public function bp_learndash_lesson_comment_approved( $comment_ID, $comment_approved, $commentdata ) {
  2.  
  3.        $comment_obj = get_comment( $comment_ID );
  4.        $post_id = $comment_obj->comment_post_ID;
  5.        $post_type = get_post_type( $post_id );
  6.      
  7.        if ( 'sfwd-lessons' == $post_type && $commentdata && 1 === $comment_approved ) {
  8.            //ONLY do if is a child comment
  9.            if ( $comment_obj->comment_parent>0 ) {
  10.                global $bp, $wpdb;
  11.                $course_id = get_post_meta($post_id,'course_id',true);
  12.                $group_attached = get_post_meta( $course_id, 'bp_course_group', true );
  13.                if ( empty( $group_attached ) ) {
  14.                    return;
  15.                    
  16.                }
  17.                if ( !bp_learndash_group_activity_is_on( 'user_lesson_comment', $group_attached ) ) {
  18.                    return;
  19.                    
  20.                }
  21.                
  22.                $user_link = bp_core_get_userlink( $comment_obj->user_id );
  23.                
  24.                $parent_ID = $comment_obj->comment_parent;
  25.                $parent_comment = get_comment($parent_ID);
  26.                $parent_usermeta = get_userdata($parent_comment->user_id);
  27.                $op_user_link = $parent_usermeta->display_name; //would be great if you could set this up as a link?
  28.          
  29.                $lesson_title = get_the_title( $post_id );
  30.                $lesson_link = get_permalink( $post_id );
  31.                $lesson_link_html = '<a href="' . esc_url( $lesson_link ) . '">' . $lesson_title . '</a>';
  32.              
  33.                $parent_comment_id = $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE content = {$parent_comment->comment_content} AND type = 'lesson_comment'" ); // This sql retreives a numeric value.
  34.              
  35.                $args = array(
  36.                              'type' => 'activity_comment',
  37.                              'action' => apply_filters( 'bp_learndash_user_lesson_comment_activity', sprintf( __( '%1$s replied to %2$s on lesson %3$s', 'buddypress-learndash' ), $user_link, $op_user_link, $lesson_link_html ), $comment_obj->user_id, $course_id ),
  38.                              'item_id' => $parent_comment_id, // This is where I want the numeric value from the database.
  39.                              'component' => $bp->groups->id,
  40.                              'secondary_item_id' => $r['parent_id'],
  41.                              'content' => $comment_obj->comment_content,
  42.                              'comment_parent' => '1',
  43.                              'mptt_left' => '',
  44.                              'mptt_right' => ''
  45.                              );
  46.              
  47.  
  48.                $activity_recorded = bp_learndash_record_activity( $args );
  49.                
  50.                if($activity_recorded) {
  51.                    bp_activity_add_meta($activity_recorded, 'bp_learndash_group_activity_markup_courseid', $post_id );
  52.                    
  53.                }
  54.                
  55.            }
  56.            }
  57.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement