Skip to:
Content

bbPress.org


Ignore:
Timestamp:
11/08/2012 10:24:15 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Capabilities:

  • Introduce bbp_user_has_profile() function in /users/capabilities.php.
  • Use this function to suppress links to a profile of a user with no role on the site.
  • Replaces some logic in bbp_parse_query() for setting user profile query variables.
  • See #1939.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/users/capabilities.php

    r4355 r4363  
    161161 * @since bbPress (r3380)
    162162 *
    163  * @uses bbp_allow_global_access()
    164  * @uses bbp_is_user_inactive()
    165  * @uses is_user_logged_in()
    166  * @uses is_user_member_of_blog()
     163 * @uses is_user_logged_in() To bail if user is not logged in
     164 * @uses bbp_get_user_role() To bail if user already has a role
     165 * @uses bbp_is_user_inactive() To bail if user is inactive
     166 * @uses bbp_allow_global_access() To know whether to save role to database
     167 * @uses bbp_get_user_role_map() To get the WP to BBP role map array
     168 * @uses bbp_get_default_role() To get the site's default forums role
    167169 * @uses get_option()
    168170 *
     
    573575        return !bbp_is_user_active( $user_id );
    574576}
     577
     578/**
     579 * Does a user have a profile for the current site
     580 *
     581 * @since bbPress (r4362)
     582 *
     583 * @param int $user_id User ID to check
     584 * @param int $blog_id Blog ID to check
     585 *
     586 * @uses bbp_get_user_id() To verify the user ID
     587 * @uses get_userdata() To get the user's data
     588 * @uses is_super_admin() To determine if user can see inactive users
     589 * @uses bbp_is_user_inactive() To check if user is spammer or deleted
     590 * @uses apply_filters() To allow override of this functions result
     591 *
     592 * @return boolean Whether or not the user has a profile on this blog_id
     593 */
     594function bbp_user_has_profile( $user_id = 0 ) {
     595
     596        // Validate user ID, default to displayed or current user
     597        $user_id = bbp_get_user_id( $user_id, true, true );
     598
     599        // Try to get this user's data
     600        $user    = get_userdata( $user_id );
     601
     602        // No user found, return false
     603        if ( empty( $user ) ) {
     604                $retval = false;
     605
     606        // User found
     607        } else {
     608
     609                // User is inactive, and current user is not a super admin
     610                if ( ! is_super_admin() && bbp_is_user_inactive( $user->ID ) ) {
     611                        $retval = false;
     612
     613                // Check for site caps
     614                } else {
     615                        $retval  = (bool) bbp_get_user_role( $user_id );
     616                }
     617        }
     618
     619        // Filter and return
     620        return (bool) apply_filters( 'bbp_show_user_profile', $retval, $user_id );
     621}
Note: See TracChangeset for help on using the changeset viewer.