Skip to:
Content

BuddyPress.org

Changeset 13236


Ignore:
Timestamp:
02/18/2022 11:06:15 PM (2 years ago)
Author:
r-a-y
Message:

Blogs: Fix pagination in BP_Blogs_Blog::get().

As part of #8488, we refactored BP_Blogs_Blog::get() to use an array
as the main function argument instead of passing multiple function
arguments.

In BP_Blogs_Blog::get(), the "per page" argument was previously
$limit, while in bp_blogs_get_blogs(), the "per page" argument
passed to BP_Blogs_Blog::get() is $r['per_page']. When swapping
over to the array function argument, $r['limit'] does not exist,
which broke pagination and would return all blogs instead.

This commit fixes the pagination problem by renaming the array key
from $r['limit'] to $r['per_page'].

Props imath.

Fixes #8633 (trunk)

Location:
trunk/src/bp-blogs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-functions.php

    r13184 r13236  
    12541254 * @see BP_Blogs_Blog::get() for a description of parameters and return values.
    12551255 *
    1256  * @param int|null $limit See {@BP_Blogs_Blog::get()}.
     1256 * @param int|null $per_page See {@BP_Blogs_Blog::get()}.
    12571257 * @param int|null $page  See {@BP_Blogs_Blog::get()}.
    12581258 * @return array See {@BP_Blogs_Blog::get()}.
    12591259 */
    1260 function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
     1260function bp_blogs_get_random_blogs( $per_page = null, $page = null ) {
    12611261    return BP_Blogs_Blog::get(
    12621262        array(
    1263             'type'  => 'random',
    1264             'limit' => $limit,
    1265             'page'  => $page
     1263            'type'     => 'random',
     1264            'per_page' => $per_page,
     1265            'page'     => $page
    12661266        )
    12671267    );
  • trunk/src/bp-blogs/classes/class-bp-blogs-blog.php

    r13184 r13236  
    171171     *     @type string      $type              The order in which results should be returned.
    172172     *                                          'active', 'alphabetical', 'newest', or 'random'.
    173      *     @type int|bool    $limit             Optional. The maximum records to return.
     173     *     @type int|bool    $per_page          Optional. The number of records to return per page.
    174174     *                                          Default: false.
    175175     *     @type int|bool    $page              Optional. The page of records to return.
     
    201201            $old_args_keys = [
    202202                0  => 'type',
    203                 1  => 'limit',
     203                1  => 'per_page',
    204204                2  => 'page',
    205205                3  => 'user_id',
     
    218218            array(
    219219                'type'              => 'active',
    220                 'limit'             => false,
     220                'per_page'          => false,
    221221                'page'              => false,
    222222                'user_id'           => 0,
     
    234234        }
    235235
    236         $pag_sql = ( $r['limit'] && $r['page'] ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $r['page'] - 1 ) * $r['limit']), intval( $r['limit'] ) ) : '';
     236        $pag_sql = ( $r['per_page'] && $r['page'] ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $r['page'] - 1 ) * $r['per_page']), intval( $r['per_page'] ) ) : '';
    237237
    238238        $user_sql = ! empty( $r['user_id'] ) ? $wpdb->prepare( " AND b.user_id = %d", $r['user_id'] ) : '';
Note: See TracChangeset for help on using the changeset viewer.