Esempio n. 1
0
 public function test_get_hidden_field_types_for_user_admin()
 {
     $duser = $this->factory->user->create();
     $cuser = $this->factory->user->create();
     $this->grant_bp_moderate($cuser);
     $old_current_user = bp_loggedin_user_id();
     $this->set_current_user($cuser);
     $this->assertEquals(array(), bp_xprofile_get_hidden_field_types_for_user($duser, bp_loggedin_user_id()));
     $this->revoke_bp_moderate($cuser);
     $this->set_current_user($old_current_user);
 }
/**
 * Get the ids of fields that are hidden for this displayed/loggedin user pair
 *
 * This is the function primarily responsible for profile field visibility. It works by determining
 * the relationship between the displayed_user (ie the profile owner) and the current_user (ie the
 * profile viewer). Then, based on that relationship, we query for the set of fields that should
 * be excluded from the profile loop.
 *
 * @since BuddyPress (1.6.0)
 * @see BP_XProfile_Group::get()
 * @uses apply_filters() Filter bp_xprofile_get_hidden_fields_for_user to modify visibility levels,
 *   or if you have added your own custom levels
 *
 * @param int $displayed_user_id The id of the user the profile fields belong to
 * @param int $current_user_id The id of the user viewing the profile
 * @return array An array of field ids that should be excluded from the profile query
 */
function bp_xprofile_get_hidden_fields_for_user($displayed_user_id = 0, $current_user_id = 0)
{
    if (!$displayed_user_id) {
        $displayed_user_id = bp_displayed_user_id();
    }
    if (!$displayed_user_id) {
        return array();
    }
    if (!$current_user_id) {
        $current_user_id = bp_loggedin_user_id();
    }
    // @todo - This is where you'd swap out for current_user_can() checks
    $hidden_levels = bp_xprofile_get_hidden_field_types_for_user($displayed_user_id, $current_user_id);
    $hidden_fields = bp_xprofile_get_fields_by_visibility_levels($displayed_user_id, $hidden_levels);
    /**
     * Filters the ids of fields that are hidden for this displayed/loggedin user pair.
     *
     * @since BuddyPress (1.6.0)
     *
     * @param array $hidden_fields     Array of hidden fields for the displayed/logged in user.
     * @param int   $displayed_user_id ID of the displayed user.
     * @param int   $current_user_id   ID of the current user.
     */
    return apply_filters('bp_xprofile_get_hidden_fields_for_user', $hidden_fields, $displayed_user_id, $current_user_id);
}
/**
 * Get the ids of fields that are hidden for this displayed/loggedin user pair
 *
 * This is the function primarily responsible for profile field visibility. It works by determining
 * the relationship between the displayed_user (ie the profile owner) and the current_user (ie the
 * profile viewer). Then, based on that relationship, we query for the set of fields that should
 * be excluded from the profile loop.
 *
 * @since BuddyPress (1.6)
 * @see BP_XProfile_Group::get()
 * @uses apply_filters() Filter bp_xprofile_get_hidden_fields_for_user to modify visibility levels,
 *   or if you have added your own custom levels
 *
 * @param int $displayed_user_id The id of the user the profile fields belong to
 * @param int $current_user_id The id of the user viewing the profile
 * @return array An array of field ids that should be excluded from the profile query
 */
function bp_xprofile_get_hidden_fields_for_user($displayed_user_id = 0, $current_user_id = 0)
{
    if (!$displayed_user_id) {
        $displayed_user_id = bp_displayed_user_id();
    }
    if (!$displayed_user_id) {
        return array();
    }
    if (!$current_user_id) {
        $current_user_id = bp_loggedin_user_id();
    }
    // @todo - This is where you'd swap out for current_user_can() checks
    $hidden_levels = bp_xprofile_get_hidden_field_types_for_user($displayed_user_id, $current_user_id);
    $hidden_fields = bp_xprofile_get_fields_by_visibility_levels($displayed_user_id, $hidden_levels);
    return apply_filters('bp_xprofile_get_hidden_fields_for_user', $hidden_fields, $displayed_user_id, $current_user_id);
}