Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/13/2021 06:54:07 PM (2 years ago)
Author:
espellcaste
Message:

Adding support to paginate messages/recipients to the BP_Messages_Box_Template class.

When querying threads using the BP_Messages_Box_Template class, one might set a default of messages/recipients, instead of returning all items.

Fixes #8597

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/classes/class-bp-messages-thread.php

    r13147 r13148  
    545545     * @param array $args {
    546546     *     Array of arguments.
    547      *     @type int    $user_id      The user ID.
    548      *     @type string $box          The type of mailbox to get. Either 'inbox' or 'sentbox'.
    549      *                                Defaults to 'inbox'.
    550      *     @type string $type         The type of messages to get. Either 'all' or 'unread'
    551      *                                or 'read'. Defaults to 'all'.
    552      *     @type int    $limit        The number of messages to get. Defaults to null.
    553      *     @type int    $page         The page number to get. Defaults to null.
    554      *     @type string $search_terms The search term to use. Defaults to ''.
    555      *     @type array  $meta_query   Meta query arguments. See WP_Meta_Query for more details.
     547     *     @type int      $user_id             The user ID.
     548     *     @type string   $box                 The type of mailbox to get. Either 'inbox' or 'sentbox'.
     549     *                                         Defaults to 'inbox'.
     550     *     @type string   $type                The type of messages to get. Either 'all' or 'unread'
     551     *                                         or 'read'. Defaults to 'all'.
     552     *     @type int      $limit               The number of messages to get. Defaults to null.
     553     *     @type int      $page                The page number to get. Defaults to null.
     554     *     @type string   $search_terms        The search term to use. Defaults to ''.
     555     *     @type array    $meta_query          Meta query arguments. See WP_Meta_Query for more details.
     556     *     @type int|null $recipients_page     Page of recipients being requested. Default to null, meaning all.
     557     *     @type int|null $recipients_per_page Recipients to return per page. Defaults to null, meaning all.
     558     *     @type int|null $messages_page       Page of messages being requested. Default to null, meaning all.
     559     *     @type int|null $messages_per_page   Messages to return per page. Defaults to null, meaning all.
    556560     * }
    557      * @return array|bool Array on success. Boolean false on failure.
     561     * @return array|bool Array on success. False on failure.
    558562     */
    559563    public static function get_current_threads_for_user( $args = array() ) {
     
    590594            $args,
    591595            array(
    592                 'user_id'      => false,
    593                 'box'          => 'inbox',
    594                 'type'         => 'all',
    595                 'limit'        => null,
    596                 'page'         => null,
    597                 'search_terms' => '',
    598                 'meta_query'   => array(),
     596                'user_id'             => false,
     597                'box'                 => 'inbox',
     598                'type'                => 'all',
     599                'limit'               => null,
     600                'page'                => null,
     601                'recipients_page'     => null,
     602                'recipients_per_page' => null,
     603                'messages_page'       => null,
     604                'messages_per_page'   => null,
     605                'search_terms'        => '',
     606                'meta_query'          => array(),
    599607            )
    600608        );
     
    603611        $meta_query_sql = array(
    604612            'join'  => '',
    605             'where' => ''
     613            'where' => '',
    606614        );
    607615
     
    627635
    628636        switch ( $r['box'] ) {
    629             case 'sentbox' :
     637            case 'sentbox':
    630638                $user_id_sql = 'AND ' . $wpdb->prepare( 'm.sender_id = %d', $r['user_id'] );
    631639                $sender_sql  = 'AND m.sender_id = r.user_id';
    632640                break;
    633641
    634             case 'inbox' :
     642            case 'inbox':
    635643                $user_id_sql = 'AND ' . $wpdb->prepare( 'r.user_id = %d', $r['user_id'] );
    636644                $sender_sql  = 'AND r.sender_only = 0';
    637645                break;
    638646
    639             default :
     647            default:
    640648                // Omit user-deleted threads from all other custom message boxes.
    641649                $deleted_sql = $wpdb->prepare( '( r.user_id = %d AND r.is_deleted = 0 )', $r['user_id'] );
     
    681689        $threads = array();
    682690        foreach ( (array) $sorted_threads as $thread_id => $date_sent ) {
    683             $threads[] = new BP_Messages_Thread( $thread_id, 'ASC', array(
    684                 'update_meta_cache' => false
    685             ) );
     691            $threads[] = new BP_Messages_Thread(
     692                $thread_id,
     693                'ASC',
     694                array(
     695                    'update_meta_cache'   => false,
     696                    'recipients_page'     => $r['recipients_page'],
     697                    'recipients_per_page' => $r['recipients_per_page'],
     698                    'page'                => $r['messages_page'],
     699                    'per_page'            => $r['messages_per_page'],
     700                )
     701            );
    686702        }
    687703
     
    695711         *     @type int   $total_threads Number of threads found by the query.
    696712         * }
     713         *  @param array $r    Array of paremeters.
    697714         */
    698         return apply_filters( 'bp_messages_thread_current_threads', array(
    699             'threads' => &$threads,
    700             'total'   => (int) $total_threads
    701         ) );
     715        return apply_filters(
     716            'bp_messages_thread_current_threads',
     717            array(
     718                'threads' => &$threads,
     719                'total'   => (int) $total_threads,
     720            ),
     721            $r
     722        );
    702723    }
    703724
Note: See TracChangeset for help on using the changeset viewer.