Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function bp_learndash_lesson_comment_approved( $comment_ID, $comment_approved, $commentdata ) {
- $comment_obj = get_comment( $comment_ID );
- $post_id = $comment_obj->comment_post_ID;
- $post_type = get_post_type( $post_id );
- if ( 'sfwd-lessons' == $post_type && $commentdata && 1 === $comment_approved ) {
- //ONLY do if is a child comment
- if ( $comment_obj->comment_parent>0 ) {
- global $bp, $wpdb;
- $course_id = get_post_meta($post_id,'course_id',true);
- $group_attached = get_post_meta( $course_id, 'bp_course_group', true );
- if ( empty( $group_attached ) ) {
- return;
- }
- if ( !bp_learndash_group_activity_is_on( 'user_lesson_comment', $group_attached ) ) {
- return;
- }
- $user_link = bp_core_get_userlink( $comment_obj->user_id );
- $parent_ID = $comment_obj->comment_parent;
- $parent_comment = get_comment($parent_ID);
- $parent_usermeta = get_userdata($parent_comment->user_id);
- $op_user_link = $parent_usermeta->display_name; //would be great if you could set this up as a link?
- $lesson_title = get_the_title( $post_id );
- $lesson_link = get_permalink( $post_id );
- $lesson_link_html = '<a href="' . esc_url( $lesson_link ) . '">' . $lesson_title . '</a>';
- $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.
- $args = array(
- 'type' => 'activity_comment',
- '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 ),
- 'item_id' => $parent_comment_id, // This is where I want the numeric value from the database.
- 'component' => $bp->groups->id,
- 'secondary_item_id' => $r['parent_id'],
- 'content' => $comment_obj->comment_content,
- 'comment_parent' => '1',
- 'mptt_left' => '',
- 'mptt_right' => ''
- );
- $activity_recorded = bp_learndash_record_activity( $args );
- if($activity_recorded) {
- bp_activity_add_meta($activity_recorded, 'bp_learndash_group_activity_markup_courseid', $post_id );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement