Skip to:
Content

BuddyPress.org

Changeset 5797


Ignore:
Timestamp:
02/16/2012 10:07:10 PM (13 years ago)
Author:
boonebgorges
Message:

Adds a toggle that allows admins to force a default visibility for a given profile field.
Prevents users from seeing the visibility customization markup when a field's visibility is forced.
Modifies appearance of visibility toggles/messages in edit.php.
Introduces bp-xprofile-caps.php to accomplish all of this.
Fixes #4015

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-hooks.php

    r5774 r5797  
    7777add_action( 'admin_bar_menu', 'bp_setup_admin_bar', 11 );
    7878
     79/** Roles and Capabilities ****************************************************/
     80
     81// Map our custom capabilities onto WP's
     82add_filter( 'map_meta_cap', 'bp_map_meta_caps', 10, 4 );
     83
    7984/** The hooks *****************************************************************/
    8085
  • trunk/bp-themes/bp-default/_inc/css/default.css

    r5792 r5797  
    23852385    font-weight: bold;
    23862386}
     2387.field-visibility-settings,
     2388.field-visibility-settings-toggle,
     2389.field-visibility-settings-notoggle {
     2390    color: #888;
     2391}
    23872392.field-visibility-settings-toggle a,
    23882393.field-visibility-settings a {
  • trunk/bp-themes/bp-default/members/single/profile/edit.php

    r5792 r5797  
    114114                <?php endif; ?>
    115115               
    116                 <?php /* The fullname field is always public */ ?>
    117                 <?php if ( 1 != bp_get_the_profile_field_id() ) : ?>
     116                <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?>
    118117                    <div class="field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>">
    119118                        <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?> <a href="#" class="visibility-toggle-link">Change</a>
     
    127126                        <a class="field-visibility-settings-close" href="#"><?php _e( 'Close', 'buddypress' ) ?></a>
    128127                    </div>
     128                <?php else : ?>
     129                    <div class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>">
     130                        <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?>
     131                    </div>         
    129132                <?php endif ?>
    130133
  • trunk/bp-xprofile/bp-xprofile-admin.php

    r5792 r5797  
    274274                if ( !empty( $_POST['default-visibility'] ) ) {
    275275                    bp_xprofile_update_field_meta( $field_id, 'default_visibility', $_POST['default-visibility'] );
     276                }
     277               
     278                if ( !empty( $_POST['allow-custom-visibility'] ) ) {
     279                    bp_xprofile_update_field_meta( $field_id, 'allow_custom_visibility', $_POST['allow-custom-visibility'] );
    276280                }
    277281
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r5796 r5797  
    284284   
    285285    /**
    286      * Fetch the field visibility level for the returned fielddata
     286     * Fetch the field visibility level for the fields returned by the query
     287     *
     288     * @since 1.6
     289     *
     290     * @param int $user_id The profile owner's user_id
     291     * @param array $fields The database results returned by the get() query
     292     * @return array $fields The database results, with field_visibility added
    287293     */
    288294    function fetch_visibility_level( $user_id, $fields ) {
     
    292298        $visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true );
    293299       
     300        // Get the admin-set preferences
     301        $admin_set_levels  = self::fetch_default_visibility_levels();
     302       
    294303        foreach( (array)$fields as $key => $field ) {
     304            // Does the admin allow this field to be customized?
     305            $allow_custom = !empty( $admin_set_levels[$field->id]['allow_custom'] ) && 'disabled' != $admin_set_levels[$field->id]['allow_custom'];
     306           
    295307            // Look to see if the user has set the visibility for this field
    296             if ( isset( $visibility_levels[$field->id] ) ) {
     308            if ( $allow_custom && isset( $visibility_levels[$field->id] ) ) {
    297309                $field_visibility = $visibility_levels[$field->id];
    298             } else {
    299                 // If not, bring up the admin-set defaults
    300                 if ( !isset( $default_visibility_levels ) ) {
    301                     $default_visibility_levels = self::fetch_default_visibility_levels();
    302                 }
    303                
     310            } else {               
    304311                // If no admin-set default is saved, fall back on a global default
    305                 $field_visibility = !empty( $default_visibility_levels[$field->id] ) ? $default_visibility_levels[$field->id] : apply_filters( 'bp_xprofile_default_visibility_level', 'public' );
     312                $field_visibility = !empty( $admin_set_levels[$field->id]['default'] ) ? $admin_set_levels[$field->id]['default'] : apply_filters( 'bp_xprofile_default_visibility_level', 'public' );
    306313            }
    307314           
     
    313320   
    314321    /**
    315      * Fetch the admin-set default visibility levels for all fields
     322     * Fetch the admin-set preferences for all fields
     323     *
     324     * @since 1.6
     325     *
     326     * @return array $default_visibility_levels An array, keyed by field_id, of default
     327     *   visibility level + allow_custom (whether the admin allows this field to be set by user)
    316328     */
    317329    function fetch_default_visibility_levels() {
    318330        global $wpdb, $bp;
    319331       
    320         $levels = $wpdb->get_results( $wpdb->prepare( "SELECT object_id, meta_value FROM {$bp->profile->table_name_meta} WHERE object_type = 'field' AND meta_key = 'default_visibility'" ) );
     332        $levels = $wpdb->get_results( $wpdb->prepare( "SELECT object_id, meta_key, meta_value FROM {$bp->profile->table_name_meta} WHERE object_type = 'field' AND ( meta_key = 'default_visibility' OR meta_key = 'allow_custom_visibility' )" ) );
    321333       
    322334        // Arrange so that the field id is the key and the visibility level the value
    323335        $default_visibility_levels = array();
    324336        foreach( $levels as $level ) {
    325             $default_visibility_levels[$level->object_id] = $level->meta_value;
     337            if ( 'default_visibility' == $level->meta_key ) {
     338                $default_visibility_levels[$level->object_id]['default'] = $level->meta_value;     
     339            } else if ( 'allow_custom_visibility' == $level->meta_key ) {
     340                $default_visibility_levels[$level->object_id]['allow_custom'] = $level->meta_value;     
     341            }
    326342        }
    327343       
     
    409425    var $is_default_option;
    410426    var $default_visibility;
     427    var $allow_custom_visibility;
    411428
    412429    var $data;
     
    452469                $this->default_visibility = 'public';
    453470            }
     471           
     472            $this->allow_custom_visibility = 'disabled' == bp_xprofile_get_meta( $id, 'field', 'allow_custom_visibility' ) ? 'disabled' : 'allowed';
    454473        }
    455474    }
     
    867886
    868887                        <div id="titlediv">
    869                             <h3><label for="default-visibility"><?php _e( "Default Visibility Level", 'buddypress' ); ?></label></h3>
     888                           
    870889                            <div id="titlewrap">
     890                                <h3><label for="default-visibility"><?php _e( "Default Visibility", 'buddypress' ); ?></label></h3>
    871891                                <ul>
    872892                                <?php foreach( bp_xprofile_get_visibility_levels() as $level ) : ?>
    873893                                    <li><input type="radio" name="default-visibility" value="<?php echo esc_attr( $level['id'] ) ?>" <?php checked( $this->default_visibility, $level['id'] ) ?>> <?php echo esc_html( $level['label'] ) ?></li>
    874894                                <?php endforeach ?>
     895                                </ul>
     896                            </div>
     897                           
     898                            <div id="titlewrap">
     899                                <h3><label for="allow-custom-visibility"><?php _e( "Per-Member Visibility", 'buddypress' ); ?></label></h3>
     900                                <ul>
     901                                    <li><input type="radio" name="allow-custom-visibility" value="allowed" <?php checked( $this->allow_custom_visibility, 'allowed' ) ?>> <?php _e( "Let members change the this field's visibility", 'buddypress' ) ?></li>
     902                                   
     903                                    <li><input type="radio" name="allow-custom-visibility" value="disabled" <?php checked( $this->allow_custom_visibility, 'disabled' ) ?>> <?php _e( 'Enforce the default visibility for all members', 'buddypress' ) ?></li>
    875904                                </ul>
    876905                            </div>
  • trunk/bp-xprofile/bp-xprofile-filters.php

    r5729 r5797  
    212212add_filter( 'comments_array', 'xprofile_filter_comments', 10, 2 );
    213213
     214
     215
    214216?>
  • trunk/bp-xprofile/bp-xprofile-loader.php

    r5792 r5797  
    4545            'activity',
    4646            'screens',
     47            'caps',
    4748            'classes',
    4849            'filters',
Note: See TracChangeset for help on using the changeset viewer.