Skip to:
Content

BuddyPress.org

Ticket #4440: 4440.001.patch

File 4440.001.patch, 3.5 KB (added by DJPaul, 13 years ago)
  • bp-xprofile/bp-xprofile-functions.php

    function bp_xprofile_get_hidden_fields_for_user( $displayed_user_id = 0, $curren 
    671671        }
    672672
    673673        // @todo - This is where you'd swap out for current_user_can() checks
     674        $hidden_levels = array();
    674675
     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();
    680681
    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();
     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 );
    684688
     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        }
    696704
    function bp_xprofile_get_hidden_fields_for_user( $displayed_user_id = 0, $curren 
    704712 * @see bp_xprofile_get_hidden_fields_for_user()
    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
    710718 */
  • bp-xprofile/bp-xprofile-loader.php

    class BP_XProfile_Component extends BP_Component { 
    101101
    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
    114118                if ( bp_is_active( 'friends' ) ) {