Skip to:
Content

bbPress.org

Changeset 4363


Ignore:
Timestamp:
11/08/2012 10:24:15 PM (12 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.
Location:
trunk/includes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/core/template-functions.php

    r4327 r4363  
    317317        }
    318318
    319         // Create new user
    320         $user = get_userdata( $bbp_user );
    321 
    322         // 404 and bail if no user found, is inactive, or not a member
    323         if ( empty( $user ) || ! is_user_member_of_blog( $user->ID ) || ( ! is_super_admin() && bbp_is_user_inactive( $user->ID ) ) ) {
     319        // Cast as int, just in case
     320        $bbp_user = (int) $bbp_user;
     321
     322        // 404 and bail if user does not have a profile
     323        if ( ! bbp_user_has_profile( $bbp_user ) ) {
    324324            $posts_query->set_404();
    325325            return;
     
    386386        // Correct is_home variable
    387387        $posts_query->is_home = false;
     388
     389        // Get the user data
     390        $user = get_userdata( $bbp_user );
    388391
    389392        // User is looking at their own profile
  • trunk/includes/replies/template-tags.php

    r4331 r4363  
    10401040
    10411041            // Add links if not anonymous
    1042             if ( empty( $anonymous ) ) {
     1042            if ( empty( $anonymous ) && bbp_user_has_profile( bbp_get_reply_author_id( $reply_id ) ) ) {
    10431043                foreach ( $author_links as $link => $link_text ) {
    10441044                    $link_class = ' class="bbp-author-' . $link . '"';
  • trunk/includes/topics/template-tags.php

    r4331 r4363  
    13601360
    13611361            // Add links if not anonymous
    1362             if ( empty( $anonymous ) ) {
     1362            if ( empty( $anonymous ) && bbp_user_has_profile( bbp_get_topic_author_id( $topic_id ) ) ) {
    13631363
    13641364                // Assemble the links
  • 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}
  • trunk/includes/users/template-tags.php

    r4352 r4363  
    13921392
    13931393            // Add links if not anonymous
    1394             if ( empty( $anonymous ) ) {
     1394            if ( empty( $anonymous ) && bbp_user_has_profile( $user_id ) ) {
    13951395                foreach ( $author_links as $link_text ) {
    13961396                    $author_link[] = sprintf( '<a href="%1$s"%2$s>%3$s</a>', $author_url, $link_title, $link_text );
Note: See TracChangeset for help on using the changeset viewer.