Changeset 6446 for trunk/src/includes/topics/functions.php
- Timestamp:
- 06/01/2017 02:53:56 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/topics/functions.php
r6438 r6446 2979 2979 } 2980 2980 2981 // Delete all engagements2982 delete_post_meta( $topic_id, '_bbp_engagement' );2983 2984 2981 // Query the DB to get voices in this topic 2982 // See: https://bbpress.trac.wordpress.org/ticket/3083 2985 2983 $bbp_db = bbp_db(); 2986 $sql = "SELECT DISTINCT post_author FROM {$bbp_db->posts} WHERE ( post_parent = %d AND post_status = %s AND post_type = %s ) OR ( ID = %d AND post_type = %s )"; 2987 $query = $bbp_db->prepare( $sql, $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ); 2984 $sql = "SELECT DISTINCT( post_author ) FROM ( 2985 SELECT post_author FROM {$bbp_db->posts} 2986 WHERE ( ID = %d AND post_type = %s ) 2987 UNION 2988 SELECT post_author FROM {$bbp_db->posts} 2989 WHERE ( post_parent = %d AND post_status = %s AND post_type = %s ) 2990 ) as u1"; 2991 $query = $bbp_db->prepare( $sql, $topic_id, bbp_get_topic_post_type(), $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type() ); 2988 2992 $results = $bbp_db->get_col( $query ); 2989 2993 2990 2994 // Parse results into voices 2991 $ voices = ! is_wp_error( $results )2995 $new_voices = ! is_wp_error( $results ) 2992 2996 ? wp_parse_id_list( array_filter( $results ) ) 2993 2997 : array(); 2994 2998 2999 // Get the old voices 3000 $old_voices = bbp_get_topic_engagements( $topic_id ); 3001 3002 // Get the count 3003 $new_count = count( $new_voices ); 3004 $old_count = count( $old_voices ); 3005 3006 // Only recalculate if count is different 3007 if ( $new_count !== $old_count ) { 3008 3009 // Delete all engagements 3010 delete_post_meta( $topic_id, '_bbp_engagement' ); 3011 3012 // Update the voice count for this topic id 3013 foreach ( $new_voices as $user_id ) { 3014 bbp_add_user_engagement( $user_id, $topic_id ); 3015 } 3016 } 3017 2995 3018 // Update the voice count for this topic id 2996 foreach ( $voices as $user_id ) { 2997 bbp_add_user_engagement( $user_id, $topic_id ); 2998 } 2999 3000 // Get the count 3001 $count = count( $voices ); 3002 3003 // Update the voice count for this topic id 3004 update_post_meta( $topic_id, '_bbp_voice_count', $count ); 3019 update_post_meta( $topic_id, '_bbp_voice_count', $new_count ); 3005 3020 3006 3021 // Filter & return 3007 return (int) apply_filters( 'bbp_update_topic_voice_count', $ count, $topic_id );3022 return (int) apply_filters( 'bbp_update_topic_voice_count', $new_count, $topic_id ); 3008 3023 } 3009 3024
Note: See TracChangeset
for help on using the changeset viewer.