Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/15/2012 08:33:09 PM (15 years ago)
Author:
boonebgorges
Message:

First pass at per-field visibility/privacy for XProfile:

  • Allows admins to set default levels for specific fields
  • Allows users to set visibility/privacy on a field-by-field basis
  • Modifies the profile templates to show markup for editing visibility status

See #3695

File:
1 edited

Legend:

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

    r5762 r5789  
    2525        var $user_id;
    2626
    27         function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) {
     27        function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false, $fetch_privacy_level = false ) {
    2828                $this->groups = BP_XProfile_Group::get( array(
    29                         'profile_group_id'  => $profile_group_id,
    30                         'user_id'           => $user_id,
    31                         'hide_empty_groups' => $hide_empty_groups,
    32                         'hide_empty_fields' => $hide_empty_fields,
    33                         'fetch_fields'      => $fetch_fields,
    34                         'fetch_field_data'  => $fetch_field_data,
    35                         'exclude_groups'    => $exclude_groups,
    36                         'exclude_fields'    => $exclude_fields
     29                        'profile_group_id'    => $profile_group_id,
     30                        'user_id'             => $user_id,
     31                        'hide_empty_groups'   => $hide_empty_groups,
     32                        'hide_empty_fields'   => $hide_empty_fields,
     33                        'fetch_fields'        => $fetch_fields,
     34                        'fetch_field_data'    => $fetch_field_data,
     35                        'fetch_privacy_level' => $fetch_privacy_level,
     36                        'exclude_groups'      => $exclude_groups,
     37                        'exclude_fields'      => $exclude_fields
    3738                ) );
    3839
    … …  
    157158        // or this is a registration page
    158159        $hide_empty_fields_default = ( !is_network_admin() && !is_admin() && !bp_is_user_profile_edit() && !bp_is_register_page() );
    159 
     160       
     161        // We only need to fetch privacy levels when viewing your own profile
     162        if ( bp_is_my_profile() || bp_current_user_can( 'bp_moderate' ) ) {
     163                $fetch_privacy_level_default = true;
     164        } else {
     165                $fetch_privacy_level_default = false;
     166        }
     167       
    160168        $defaults = array(
    161                 'user_id'           => bp_displayed_user_id(),
    162                 'profile_group_id'  => false,
    163                 'hide_empty_groups' => true,
    164                 'hide_empty_fields' => $hide_empty_fields_default,
    165                 'fetch_fields'      => true,
    166                 'fetch_field_data'  => true,
    167                 'exclude_groups'    => false, // Comma-separated list of profile field group IDs to exclude
    168                 'exclude_fields'    => false  // Comma-separated list of profile field IDs to exclude
     169                'user_id'             => bp_displayed_user_id(),
     170                'profile_group_id'    => false,
     171                'hide_empty_groups'   => true,
     172                'hide_empty_fields'   => $hide_empty_fields_default,
     173                'fetch_fields'        => true,
     174                'fetch_field_data'    => true,
     175                'fetch_privacy_level' => $fetch_privacy_level_default,
     176                'exclude_groups'      => false, // Comma-separated list of profile field group IDs to exclude
     177                'exclude_fields'      => false  // Comma-separated list of profile field IDs to exclude
    169178        );
    170179
    … …  
    172181        extract( $r, EXTR_SKIP );
    173182
    174         $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields );
     183        $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields, $fetch_privacy_level );
    175184        return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template );
    176185}
    … …  
    698707        }
    699708
     709/**
     710 * Echo the privacy level of this field
     711 */
     712function bp_the_profile_field_privacy_level() {
     713        echo bp_get_the_profile_field_privacy_level();
     714}
     715        /**
     716         * Return the privacy level of this field
     717         */
     718        function bp_get_the_profile_field_privacy_level() {
     719                global $field;
     720               
     721                $retval = !empty( $field->privacy_level ) ? $field->privacy_level : 'public';
     722               
     723                return apply_filters( 'bp_get_the_profile_field_privacy_level', $retval );
     724        }
     725
     726/**
     727 * Echo the privacy level label of this field
     728 */
     729function bp_the_profile_field_privacy_level_label() {
     730        echo bp_get_the_profile_field_privacy_level_label();
     731}
     732        /**
     733         * Return the privacy level label of this field
     734         */
     735        function bp_get_the_profile_field_privacy_level_label() {
     736                global $field;
     737               
     738                $level  = !empty( $field->privacy_level ) ? $field->privacy_level : 'public';
     739                $fields = bp_xprofile_get_privacy_levels();
     740               
     741                return apply_filters( 'bp_get_the_profile_field_privacy_level_label', $fields[$level]['label'] );
     742        }
     743
     744
    700745function bp_unserialize_profile_field( $value ) {
    701746        if ( is_serialized($value) ) {
    … …  
    840885}
    841886
     887/**
     888 * Echo the field privacy radio buttons
     889 */
     890function bp_profile_privacy_radio_buttons() {
     891        echo bp_profile_get_privacy_radio_buttons();
     892}
     893        /**
     894         * Return the field privacy radio buttons
     895         */
     896        function bp_profile_get_privacy_radio_buttons() {               
     897                $html = '<ul class="radio">';
     898               
     899                foreach( bp_xprofile_get_privacy_levels() as $level ) {
     900                        $checked = $level['id'] == bp_get_the_profile_field_privacy_level() ? ' checked="checked" ' : '';
     901                       
     902                        $html .= '<li><input type="radio" name="field_' . bp_get_the_profile_field_id() . '_privacy" value="' . esc_attr( $level['id'] ) . '"' . $checked . '> ' . esc_html( $level['label'] ) . '</li>';
     903                }
     904               
     905                $html .= '</ul>';
     906               
     907                return apply_filters( 'bp_profile_get_privacy_radio_buttons', $html );
     908        }
    842909?>
Note: See TracChangeset for help on using the changeset viewer.