Skip to:
Content

bbPress.org

Changeset 6221


Ignore:
Timestamp:
01/12/2017 09:07:18 AM (4 years ago)
Author:
johnjamesjacoby
Message:

Moderators: Update bbp_get_moderator_forum_ids() to use same approach as favs/subs.

See #459, #2959, #2972.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/forums/capabilities.php

    r6196 r6221  
    195195 *
    196196 * @param int $user_id User id.
    197  * @uses get_userdata() To get the user object
    198  * @uses get_term_by() To get the term id
    199  * @uses get_objects_in_term() Get the forums the user moderates
    200  * @uses is_wp_error() To check for errors
    201  * @uses bbp_is_forum() To make sure the objects are forums
    202197 *
    203198 * @return boolean|array Return false on error or empty, or array of forum ids
    204199 */
    205200function bbp_get_moderator_forum_ids( $user_id = 0 ) {
    206 
    207     // Default return value
    208     $retval = $forums = array();
    209 
    210     // Bail if no user ID.
    211201    $user_id = bbp_get_user_id( $user_id );
    212     if ( ! empty( $user_id ) ) {
    213 
    214         // Bail if user does not exist.
    215         $user = get_userdata( $user_id );
    216         if ( ! empty( $user ) ) {
    217 
    218             // Get the forums this user can moderate
    219             $forums = get_posts( array(
    220                 'post_type'   => bbp_get_forum_post_type(),
    221                 'meta_key'    => '_bbp_moderator_id',
    222                 'meta_type'   => 'NUMERIC',
    223                 'meta_value'  => $user_id,
    224                 'numberposts' => -1
    225             ) );
    226 
    227             // Pluck IDs
    228             if ( ! empty( $forums ) ) {
    229                 $retval = wp_list_pluck( $forums, 'ID' );
    230             }
    231         }
    232     }
     202    $forums  = new WP_Query( array(
     203        'fields'        => 'ids',
     204        'post_type'     => bbp_get_forum_post_type(),
     205        'nopaging'      => true,
     206        'no_found_rows' => true,
     207        'meta_query'    => array( array(
     208            'key'     => '_bbp_moderator_id',
     209            'value'   => $user_id,
     210            'compare' => 'NUMERIC'
     211        ) )
     212    ) );
    233213
    234214    // Filter & return
    235     return (array) apply_filters( 'bbp_get_moderator_forum_ids', $retval, $user_id, $forums );
     215    return (array) apply_filters( 'bbp_get_moderator_forum_ids', $forums->posts, $user_id, $forums );
    236216}
    237217
Note: See TracChangeset for help on using the changeset viewer.