Skip to:
Content

BuddyPress.org

Changeset 7924


Ignore:
Timestamp:
02/18/2014 05:03:52 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Clean up bp_has_message_threads():

  • Move default box ahead of argument parsing so it can be overridden VS being forced.
  • Remove unused $bp global.
  • Use bp_parse_args() so arguments can be filtered before they are queried.
  • Pass $r into bp_has_message_threads filter.
  • Add inline documentation and phpdoc block.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-messages/bp-messages-template.php

    r7923 r7924  
    166166}
    167167
     168/**
     169 * Retrieve private message threads for display in inbox/sentbox/notices
     170 *
     171 * Similar to WordPress's have_posts() function, this function is responsible
     172 * for querying the database and retrieving private messages for display inside
     173 * the theme via individual template parts for a member's inbox/sentbox/notices.
     174 *
     175 * @since BuddyPress (1.0.0)
     176 *
     177 * @global BP_Messages_Box_Template $messages_template
     178 * @param array $args
     179 * @return object
     180 */
    168181function bp_has_message_threads( $args = '' ) {
    169     global $bp, $messages_template;
    170 
    171     $defaults = array(
     182    global $messages_template;
     183
     184    // The default box the user is looking at
     185    if ( bp_is_current_action( 'sentbox' ) ) {
     186        $default_box = 'sentbox';
     187    } elseif ( bp_is_current_action( 'notices' ) ) {
     188        $default_box = 'notices';
     189    } else {
     190        $default_box = 'inbox';
     191    }
     192
     193    // Parse the arguments
     194    $r = bp_parse_args( $args, array(
    172195        'user_id'      => bp_loggedin_user_id(),
    173         'box'          => 'inbox',
     196        'box'          => $default_box,
    174197        'per_page'     => 10,
    175198        'max'          => false,
     
    177200        'search_terms' => isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '',
    178201        'page_arg'     => 'mpage', // See https://buddypress.trac.wordpress.org/ticket/3679
    179     );
    180 
    181     $r = wp_parse_args( $args, $defaults );
    182     extract( $r, EXTR_SKIP );
    183 
     202    ), 'has_message_threads' );
     203
     204    // If trying to access notices without capabilities, redirect to root domain
    184205    if ( bp_is_current_action( 'notices' ) && !bp_current_user_can( 'bp_moderate' ) ) {
    185206        bp_core_redirect( bp_displayed_user_domain() );
    186     } else {
    187         if ( bp_is_current_action( 'sentbox' ) ) {
    188             $box = 'sentbox';
    189         }
    190 
    191         if ( bp_is_current_action( 'notices' ) ) {
    192             $box = 'notices';
    193         }
    194 
    195         $messages_template = new BP_Messages_Box_Template( $user_id, $box, $per_page, $max, $type, $search_terms, $page_arg );
    196     }
    197 
    198     return apply_filters( 'bp_has_message_threads', $messages_template->has_threads(), $messages_template );
     207    }
     208
     209    // Load the messages loop global up with messages
     210    $messages_template = new BP_Messages_Box_Template(
     211        $r['user_id'],
     212        $r['box'],
     213        $r['per_page'],
     214        $r['max'],
     215        $r['type'],
     216        $r['search_terms'],
     217        $r['page_arg']
     218    );
     219
     220    return apply_filters( 'bp_has_message_threads', $messages_template->has_threads(), $messages_template, $r );
    199221}
    200222
Note: See TracChangeset for help on using the changeset viewer.