Skip to:
Content

BuddyPress.org

Changeset 8757


Ignore:
Timestamp:
08/05/2014 03:55:31 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Clean up bp_has_blogs() a bit:

  • Remove unnecessary comparisons
  • Remove one-time use variables
  • empty() checks where appropriate
File:
1 edited

Legend:

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

    r8683 r8757  
    352352    global $blogs_template;
    353353
    354     /***
    355      * Set the defaults based on the current page. Any of these will be
    356      * overridden if arguments are directly passed into the loop. Custom
    357      * plugins should always pass their parameters directly to the loop.
    358      */
    359     $type    = 'active';
    360     $user_id = 0;
    361 
    362     // User filtering
    363     if ( bp_displayed_user_id() )
    364         $user_id = bp_displayed_user_id();
    365 
    366     if ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) ) {
    367         $search_terms = $_REQUEST['s'];
    368     } else {
    369         $search_terms = false;
    370     }
    371 
    372     $defaults = array(
    373         'type'              => $type,
     354    // Checkfor and use search terms
     355    $search_terms = ! empty( $_REQUEST['s'] )
     356        ? $_REQUEST['s']
     357        : false;
     358
     359    // Parse arguments
     360    $r = bp_parse_args( $args, array(
     361        'type'              => 'active',
     362        'page_arg'          => 'bpage',                // See https://buddypress.trac.wordpress.org/ticket/3679
    374363        'page'              => 1,
    375364        'per_page'          => 20,
    376365        'max'               => false,
    377 
    378         'page_arg'          => 'bpage',        // See https://buddypress.trac.wordpress.org/ticket/3679
    379 
    380         'user_id'           => $user_id,       // Pass a user_id to limit to only blogs this user has higher than subscriber access to
     366        'user_id'           => bp_displayed_user_id(), // Pass a user_id to limit to only blogs this user has higher than subscriber access to
    381367        'include_blog_ids'  => false,
    382         'search_terms'      => $search_terms,  // Pass search terms to filter on the blog title or description.
    383         'update_meta_cache' => true,
    384     );
    385 
    386     $r = bp_parse_args( $args, $defaults, 'has_blogs' );
    387 
    388     if ( $r['max'] ) {
    389         if ( $r['per_page'] > $r['max'] ) {
    390             $r['per_page'] = $r['max'];
    391         }
    392     }
    393 
     368        'search_terms'      => $search_terms,          // Pass search terms to filter on the blog title or description.
     369        'update_meta_cache' => true
     370    ), 'has_blogs' );
     371
     372    // Set per_page to maximum if max is enforced
     373    if ( ! empty( $r['max'] ) && ( (int) $r['per_page'] > (int) $r['max'] ) ) {
     374        $r['per_page'] = (int) $r['max'];
     375    }
     376
     377    // Get the blogs
    394378    $blogs_template = new BP_Blogs_Template( $r['type'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['search_terms'], $r['page_arg'], $r['update_meta_cache'], $r['include_blog_ids'] );
     379
     380    // Filter and return
    395381    return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), $blogs_template, $r );
    396382}
Note: See TracChangeset for help on using the changeset viewer.