Skip to:
Content

BuddyPress.org

Changeset 6352


Ignore:
Timestamp:
09/28/2012 09:52:18 PM (9 years ago)
Author:
djpaul
Message:

Add an "admins only" visibility option to profile fields. Fixes #4440

Location:
trunk/bp-xprofile
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/bp-xprofile-functions.php

    r6342 r6352  
    672672
    673673    // @todo - This is where you'd swap out for current_user_can() checks
    674 
     674    $hidden_levels = array();
     675
     676    // Current user is logged in
    675677    if ( $current_user_id ) {
    676         // Current user is logged in
     678
     679        // If you're viewing your own profile, nothing's private
    677680        if ( $displayed_user_id == $current_user_id ) {
    678             // If you're viewing your own profile, nothing's private
    679             $hidden_fields = array();
    680 
    681         } else if ( bp_is_active( 'friends' ) && friends_check_friendship( $displayed_user_id, $current_user_id ) ) {
    682             // If the current user and displayed user are friends, show all
    683             $hidden_fields = array();
    684 
     681
     682        // If the current user and displayed user are friends, show all
     683        } elseif ( bp_is_active( 'friends' ) && friends_check_friendship( $displayed_user_id, $current_user_id ) ) {
     684            if ( ! bp_current_user_can( 'bp_moderate' ) )
     685                $hidden_levels[] = 'adminsonly';
     686
     687            $hidden_fields = bp_xprofile_get_fields_by_visibility_levels( $displayed_user_id, $hidden_levels );
     688
     689        // current user is logged-in but not friends, so exclude friends-only
    685690        } else {
    686             // current user is logged-in but not friends, so exclude friends-only
    687691            $hidden_levels = array( 'friends' );
     692
     693            if ( ! bp_current_user_can( 'bp_moderate' ) )
     694                $hidden_levels[] = 'adminsonly';
     695
    688696            $hidden_fields = bp_xprofile_get_fields_by_visibility_levels( $displayed_user_id, $hidden_levels );
    689697        }
    690698
     699    // Current user is not logged in, so exclude friends-only, loggedin, and adminsonly.
    691700    } else {
    692         // Current user is not logged in, so exclude friends-only and loggedin
    693         $hidden_levels = array( 'friends', 'loggedin' );
     701        $hidden_levels = array( 'friends', 'loggedin', 'adminsonly', );
    694702        $hidden_fields = bp_xprofile_get_fields_by_visibility_levels( $displayed_user_id, $hidden_levels );
    695703    }
     
    705713 *
    706714 * @param int $user_id The id of the profile owner
    707  * @param array $levels An array of visibility levels ('public', 'friends', 'loggedin', etc) to be
     715 * @param array $levels An array of visibility levels ('public', 'friends', 'loggedin', 'adminsonly' etc) to be
    708716 *    checked against
    709717 * @return array $field_ids The fields that match the requested visibility levels for the given user
  • trunk/bp-xprofile/bp-xprofile-loader.php

    r6342 r6352  
    102102        // Register the visibility levels. See bp_xprofile_get_visibility_levels() to filter
    103103        $this->visibility_levels = array(
    104             'public'  => array(
    105                 'id'    => 'public',
     104            'public' => array(
     105                'id'      => 'public',
    106106                'label' => __( 'Anyone', 'buddypress' )
    107107            ),
    108108            'loggedin' => array(
    109                 'id'    => 'loggedin',
     109                'id'      => 'loggedin',
    110110                'label' => __( 'Logged In Users', 'buddypress' )
    111             )
     111            ),
     112            'adminsonly' => array(
     113                'id'      => 'adminsonly',
     114                'label' => __( 'Admins Only', 'buddypress' )
     115            ),
    112116        );
    113117
Note: See TracChangeset for help on using the changeset viewer.