Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/29/2015 03:36:16 PM (11 years ago)
Author:
johnjamesjacoby
Message:

Introduce bp_sanitize_pagination_arg() and related tests. This function will help sanitize our pagination request values, as they are frequently accessed via globally accessible variables for ajax requests. See #5796.

File:
1 edited

Legend:

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

    r9351 r9410  
    266266    // Return the parsed results
    267267    return $r;
     268}
     269
     270/**
     271 * Sanitizes a pagination argument based on both the request override and the
     272 * original value submitted via a query argument, likely to a template class
     273 * responsible for limiting the resultset of a template loop.
     274 *
     275 * @since BuddyPress (2.2.0)
     276 *
     277 * @param  string $page_arg The $_REQUEST argument to look for
     278 * @param  int    $page     The original page value to fall back to
     279 * @return int              A sanitized integer value, good for pagination
     280 */
     281function bp_sanitize_pagination_arg( $page_arg = '', $page = 1 ) {
     282
     283    // Check if request overrides exist
     284    if ( isset( $_REQUEST[ $page_arg ] ) ) {
     285
     286        // Get the absolute integer value of the override
     287        $int = absint( $_REQUEST[ $page_arg ] );
     288
     289        // If override is 0, do not use it. This prevents unlimited result sets.
     290        // @see https://buddypress.trac.wordpress.org/ticket/5796
     291        if ( $int ) {
     292            $page = intval( $int );
     293        }
     294    }
     295
     296    return $page;
    268297}
    269298
Note: See TracChangeset for help on using the changeset viewer.