- Timestamp:
- 11/03/2024 05:55:47 PM (8 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-messages/classes/class-bp-messages-thread.php
r14061 r14069 673 673 * 674 674 * @since 1.0.0 675 * @since 15.0.0 Added the `$includes` parameter. 675 676 * 676 677 * @global wpdb $wpdb WordPress database object. … … 685 686 * @type int $limit The number of messages to get. Defaults to null. 686 687 * @type int $page The page number to get. Defaults to null. 688 * @type array $includes Filter threads by recipient IDs. 687 689 * @type string $search_terms The search term to use. Defaults to ''. 688 690 * @type array $meta_query Meta query arguments. See WP_Meta_Query for more details. … … 731 733 'type' => 'all', 732 734 'limit' => null, 735 'includes' => array(), 733 736 'page' => null, 734 737 'recipients_page' => null, … … 741 744 ); 742 745 743 $pag_sql = $type_sql = $search_sql = $user_id_sql = $ sender_sql = '';746 $pag_sql = $type_sql = $search_sql = $user_id_sql = $includes_sql = $sender_sql = ''; 744 747 $meta_query_sql = array( 745 748 'join' => '', … … 795 798 $bp = buddypress(); 796 799 800 if ( ! empty( $r['includes'] ) && is_array( $r['includes'] ) ) { 801 $includes_ids = array_filter( 802 wp_parse_id_list( $r['includes'] ), 803 function ( $recipient_id ) use ( $r ) { 804 // Filter out the current user ID, if available. 805 return $recipient_id !== $r['user_id']; 806 } 807 ); 808 809 if ( ! empty( $includes_ids ) ) { 810 $includes_ids = implode( ',', $includes_ids ); 811 $includes_sql = "AND r.thread_id IN (SELECT thread_id FROM {$bp->messages->table_name_recipients} WHERE user_id in ({$includes_ids}))"; 812 } 813 } 814 797 815 // Set up SQL array. 798 816 $sql = array(); 799 817 $sql['select'] = 'SELECT m.thread_id, MAX(m.date_sent) AS date_sent'; 800 818 $sql['from'] = "FROM {$bp->messages->table_name_recipients} r INNER JOIN {$bp->messages->table_name_messages} m ON m.thread_id = r.thread_id {$meta_query_sql['join']}"; 801 $sql['where'] = "WHERE {$deleted_sql} {$user_id_sql} {$sender_sql} {$ type_sql} {$search_sql} {$meta_query_sql['where']}";819 $sql['where'] = "WHERE {$deleted_sql} {$user_id_sql} {$sender_sql} {$includes_sql} {$type_sql} {$search_sql} {$meta_query_sql['where']}"; 802 820 $sql['misc'] = "GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}"; 803 821 … … 811 829 $sql['select'] = 'SELECT COUNT( DISTINCT m.thread_id )'; 812 830 unset( $sql['misc'] ); 831 813 832 $total_threads = $wpdb->get_var( implode( ' ', $sql ) ); 814 833 … … 841 860 * @since 2.2.0 842 861 * 843 * @param array $ value{844 * @type array$threads Array of threads. Passed by reference.845 * @type int $total_threads Number of threads found by the query.862 * @param array $results { 863 * @type BP_Messages_Thread[] $threads Array of threads. Passed by reference. 864 * @type int $total_threads Number of threads found by the query. 846 865 * } 847 * @param array $r 866 * @param array $r Array of parameters. 848 867 */ 849 868 return apply_filters(
Note: See TracChangeset
for help on using the changeset viewer.