Changeset 6516 for trunk/src/includes/topics/functions.php
- Timestamp:
- 06/10/2017 07:25:42 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/topics/functions.php
r6504 r6516 2965 2965 * 2966 2966 * @since 2.0.0 bbPress (r2567) 2967 * @since 2.6.0 bbPress (r6515) This must be called after any engagement changes 2967 2968 * 2968 2969 * @param int $topic_id Optional. Topic id to update … … 2982 2983 function bbp_update_topic_voice_count( $topic_id = 0 ) { 2983 2984 2984 // If it's a reply, then get the parent (topic id)2985 if ( bbp_is_reply( $topic_id ) ) {2986 $topic_id = bbp_get_reply_topic_id( $topic_id );2987 } elseif ( bbp_is_topic( $topic_id ) ) {2988 $topic_id = bbp_get_topic_id( $topic_id );2989 } else {2990 return;2991 }2992 2993 // Query the DB to get voices in this topic2994 // See: https://bbpress.trac.wordpress.org/ticket/30832995 $bbp_db = bbp_db();2996 $sql = "SELECT DISTINCT( post_author ) FROM (2997 SELECT post_author FROM {$bbp_db->posts}2998 WHERE ( ID = %d AND post_type = %s )2999 UNION3000 SELECT post_author FROM {$bbp_db->posts}3001 WHERE ( post_parent = %d AND post_status = %s AND post_type = %s )3002 ) as u1";3003 $query = $bbp_db->prepare( $sql, $topic_id, bbp_get_topic_post_type(), $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type() );3004 $results = $bbp_db->get_col( $query );3005 3006 // Parse results into voices3007 $new_voices = ! is_wp_error( $results )3008 ? wp_parse_id_list( array_filter( $results ) )3009 : array();3010 3011 2985 // Get the old voices 3012 $old_voices = bbp_get_topic_engagements( $topic_id ); 3013 3014 // Get the count 3015 $new_count = count( $new_voices ); 3016 $old_count = count( $old_voices ); 3017 3018 // Only recalculate if count is different 3019 if ( $new_count !== $old_count ) { 3020 3021 // Delete all engagements 3022 delete_post_meta( $topic_id, '_bbp_engagement' ); 3023 3024 // Update the voice count for this topic id 3025 foreach ( $new_voices as $user_id ) { 3026 bbp_add_user_engagement( $user_id, $topic_id ); 3027 } 3028 } 2986 $count = count( bbp_get_topic_engagements( $topic_id ) ); 3029 2987 3030 2988 // Update the voice count for this topic id 3031 update_post_meta( $topic_id, '_bbp_voice_count', $ new_count );2989 update_post_meta( $topic_id, '_bbp_voice_count', $count ); 3032 2990 3033 2991 // Filter & return 3034 return (int) apply_filters( 'bbp_update_topic_voice_count', $ new_count, $topic_id );2992 return (int) apply_filters( 'bbp_update_topic_voice_count', $count, $topic_id ); 3035 2993 } 3036 2994
Note: See TracChangeset
for help on using the changeset viewer.