Skip to:
Content

bbPress.org

Changeset 5839


Ignore:
Timestamp:
07/15/2015 05:42:27 PM (5 years ago)
Author:
johnjamesjacoby
Message:

Moderators: Rename bbp_get_forum_mod_ids() to bbp_get_forum_moderator_ids() to better match unabbreviated forum equivalent. Also update phpdoc & refactor some logic to use cached functions. See #459.

File:
1 edited

Legend:

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

    r5834 r5839  
    253253 * @uses bbp_is_forum() To make sure it is a forum
    254254 * @uses bbp_get_forum_mod_tax_id() To get the forum moderator taxonomy
    255  * @uses wp_get_object_terms() To get the forum's moderator terms
    256  * @uses is_wp_error() To check for errors
     255 * @uses bbp_get_forum_mods() To get the forum's moderator terms
    257256 * @uses bbp_get_term_taxonomy_user_id() To convert terms to user ids
    258257 *
    259  * @return boolean|array Return false early, or if no moderator terms set, or
    260  *                 an array of User ids
    261  */
    262 function bbp_get_forum_mod_ids( $forum_id = 0 ) {
     258 * @return boolean|array Return false on error or empty, or array of user ids
     259 */
     260function bbp_get_forum_moderator_ids( $forum_id = 0 ) {
    263261
    264262    // Bail if no forum ID.
     
    274272
    275273    // Get forum taxonomy terms.
    276     $taxonomy = bbp_get_forum_mod_tax_id();
    277     $terms    = wp_get_object_terms( $forum_id, $taxonomy, array(
    278         'fields' => 'ids',
    279     ) );
     274    $terms = bbp_get_forum_mods( $forum_id );
    280275
    281276    // Bail if no terms found.
    282     if ( empty( $terms ) || is_wp_error( $terms ) ) {
    283         return false;
    284     }
    285 
    286     $moderators = array();
     277    if ( empty( $terms ) ) {
     278        return false;
     279    }
     280
     281    // Setup default values
     282    $term_ids      = wp_parse_id_list( $terms );
     283    $taxonomy      = bbp_get_forum_mod_tax_id();
     284    $moderator_ids = array();
    287285
    288286    // Convert term ids to user ids.
    289     foreach ( $terms as $term ) {
    290         $user_id = bbp_get_term_taxonomy_user_id( $term, $taxonomy );
    291         if ( ! empty( $user_id ) ) {
    292             $moderators[] = $user_id;
    293         }
    294     }
    295 
    296     // Moderators found.
    297     if ( ! empty( $moderators ) ) {
    298         return $moderators;
    299     }
    300 
    301     return false;
     287    foreach ( $term_ids as $term_id ) {
     288        $moderator_ids[] = bbp_get_term_taxonomy_user_id( $term_id, $taxonomy );
     289    }
     290
     291    // Remove empties
     292    $retval = wp_parse_id_list( array_filter( $moderator_ids ) );
     293
     294    // Filter & return
     295    return apply_filters( 'bbp_get_forum_moderator_ids', $retval, $forum_id );
    302296}
    303297
     
    316310 * @uses bbp_is_forum() To make sure the objects are forums
    317311 *
    318  * @return boolean|array Return false early, or if user has no forums, or
    319  *                 an array of Forum ids
     312 * @return boolean|array Return false on error or empty, or array of forum ids
    320313 */
    321314function bbp_get_moderator_forum_ids( $user_id = 0 ) {
    322315
    323316    // Bail if no user ID.
     317    $user_id = bbp_get_user_id( $user_id );
    324318    if ( empty( $user_id ) ) {
    325319        return false;
    326320    }
    327321
    328     // Bail if user does not eist.
     322    // Bail if user does not exist.
    329323    $user = get_userdata( $user_id );
    330324    if ( empty( $user ) ) {
     
    352346    }
    353347
    354     return $forum_ids;
     348    // Remove empties
     349    $retval = wp_parse_id_list( array_filter( $forum_ids ) );
     350
     351    // Filter & return
     352    return apply_filters( 'bbp_get_moderator_forum_ids', $retval, $user_id );
    355353}
    356354
Note: See TracChangeset for help on using the changeset viewer.