Skip to:
Content

BuddyPress.org

Changeset 8210


Ignore:
Timestamp:
03/30/2014 06:35:15 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Profile Visibility Settings:

  • Rename template functions to match existing functions (profile VS xprofile)
  • Allow passing of field_id so they can be used outside of the profile field loop.
  • Allow before/after in radio buttons output.
  • See #5352.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-templates/bp-legacy/buddypress/members/single/settings/profile.php

    r7965 r8210  
    2121                                                <tr <?php bp_field_css_class(); ?>>
    2222                                                        <td class="field-name"><?php bp_the_profile_field_name(); ?></td>
    23                                                         <td class="field-visibility"><?php bp_xprofile_settings_visibility_select(); ?></td>
     23                                                        <td class="field-visibility"><?php bp_profile_settings_visibility_select(); ?></td>
    2424                                                </tr>
    2525
  • trunk/bp-themes/bp-default/members/single/settings/profile.php

    r7965 r8210  
    7171                                                                                <tr <?php bp_field_css_class(); ?>>
    7272                                                                                        <td class="field-name"><?php bp_the_profile_field_name(); ?></td>
    73                                                                                         <td class="field-visibility"><?php bp_xprofile_settings_visibility_select(); ?></td>
     73                                                                                        <td class="field-visibility"><?php bp_profile_settings_visibility_select(); ?></td>
    7474                                                                                </tr>
    7575
  • trunk/bp-xprofile/bp-xprofile-template.php

    r8178 r8210  
    692692 * Echo the field visibility radio buttons
    693693 */
    694 function bp_profile_visibility_radio_buttons() {
    695         echo bp_profile_get_visibility_radio_buttons();
     694function bp_profile_visibility_radio_buttons( $args = '' ) {
     695        echo bp_profile_get_visibility_radio_buttons( $args );
    696696}
    697697        /**
    698698         * Return the field visibility radio buttons
    699699         */
    700         function bp_profile_get_visibility_radio_buttons() {
    701                 $html = '<ul class="radio">';
    702 
    703                 foreach( bp_xprofile_get_visibility_levels() as $level ) {
    704                         $checked = $level['id'] == bp_get_the_profile_field_visibility_level() ? ' checked="checked" ' : '';
    705 
    706                         // Only sanitize once
    707                         $field_id = bp_get_the_profile_field_id();
    708                         $level_id = esc_attr( $level['id'] );
    709 
    710                         $html .= '<li><label for="see-field_' . $field_id . '_' . $level_id . '"><input type="radio" id="see-field_' . $field_id . '_' . $level_id . '" name="field_' . $field_id . '_visibility" value="' . $level_id . '"' . $checked . ' /> ' . esc_html( $level['label'] ) . '</label></li>';
    711                 }
    712 
    713                 $html .= '</ul>';
    714 
    715                 return apply_filters( 'bp_profile_get_visibility_radio_buttons', $html );
     700        function bp_profile_get_visibility_radio_buttons( $args = '' ) {
     701
     702                // Parse optional arguments
     703                $r = bp_parse_args( $args, array(
     704                        'field_id'     => bp_get_the_profile_field_id(),
     705                        'before'       => '<ul class="radio">',
     706                        'after'        => '</ul>',
     707                        'before_radio' => '<li>',
     708                        'after_radio'  => '</li>',
     709                        'class'        => 'bp-xprofile-visibility'
     710                ), 'xprofile_visibility_radio_buttons' );
     711
     712                // Empty return value, filled in below if a valid field ID is found
     713                $retval = '';
     714
     715                // Only do-the-do if there's a valid field ID
     716                if ( ! empty( $r['field_id'] ) ) :
     717
     718                        // Start the output buffer
     719                        ob_start();
     720
     721                        // Output anything before
     722                        echo $r['before']; ?>
     723
     724                        <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?>
     725
     726                                <?php foreach( bp_xprofile_get_visibility_levels() as $level ) : ?>
     727
     728                                        <?php echo $r['before_radio']; ?>
     729
     730                                        <label for="<?php esc_attr( 'see-field_' . $r['field_id'] . '_' . $level['id'] ); ?>">
     731                                                <input type="radio" id="<?php echo esc_attr( 'see-field_' . $r['field_id'] . '_' . $level['id'] ); ?>" name="<?php echo esc_attr( 'field_' . $r['field_id'] . '_visibility' ); ?>" value="<?php echo esc_attr( $level['id'] ); ?>" <?php checked( $level['id'], bp_get_the_profile_field_visibility_level() ); ?> />
     732                                                <span class="field-visibility-text"><?php echo esc_html( $level['label'] ); ?></span>
     733                                        </label>
     734
     735                                        <?php echo $r['after_radio']; ?>
     736
     737                                <?php endforeach; ?>
     738
     739                        <?php endif;
     740
     741                        // Output anything after
     742                        echo $r['after'];
     743
     744                        // Get the output buffer and empty it
     745                        $retval = ob_get_clean();
     746                endif;
     747
     748                return apply_filters( 'bp_profile_get_visibility_radio_buttons', $retval, $r, $args );
    716749        }
    717750
    … …  
    721754 * @since BuddyPress (2.0.0)
    722755 */
    723 function bp_xprofile_settings_visibility_select( $args = '' ) {
    724         echo bp_xprofile_get_settings_visibility_select( $args );
     756function bp_profile_settings_visibility_select( $args = '' ) {
     757        echo bp_profile_get_settings_visibility_select( $args );
    725758}
    726759        /**
    … …  
    729762         * @since BuddyPress (2.0.0)
    730763         */
    731         function bp_xprofile_get_settings_visibility_select( $args = '' ) {
     764        function bp_profile_get_settings_visibility_select( $args = '' ) {
    732765
    733766                // Parse optional arguments
    734767                $r = bp_parse_args( $args, array(
    735                         'before' => '',
    736                         'after'  => '',
    737                         'class'  => 'bp-xprofile-visibility'
     768                        'field_id' => bp_get_the_profile_field_id(),
     769                        'before'   => '',
     770                        'after'    => '',
     771                        'class'    => 'bp-xprofile-visibility'
    738772                ), 'xprofile_settings_visibility_select' );
    739773
    740                 // Start the output buffer
    741                 ob_start();
    742 
    743                 // Anything before
    744                 echo $r['before']; ?>
    745 
    746                 <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?>
    747 
    748                         <select class="<?php echo esc_attr( $r['class'] ); ?>" name="field_<?php bp_the_profile_field_id(); ?>_visibility">
    749 
    750                                 <?php foreach ( bp_xprofile_get_visibility_levels() as $level ) : ?>
    751 
    752                                         <option value="<?php echo esc_attr( $level['id'] ); ?>" <?php selected( $level['id'], bp_get_the_profile_field_visibility_level() ); ?>><?php echo esc_html( $level['label'] ); ?></option>
    753 
    754                                 <?php endforeach; ?>
    755 
    756                         </select>
    757 
    758                 <?php else : ?>
    759 
    760                         <span class="field-visibility-settings-notoggle" title="<?php esc_attr_e( "This field's visibility cannot be changed.", 'buddypress' ); ?>"><?php bp_the_profile_field_visibility_level_label(); ?></span>
    761 
    762                 <?php endif;
    763 
    764                 // Anything after
    765                 echo $r['after'];
     774                // Empty return value, filled in below if a valid field ID is found
     775                $retval = '';
     776
     777                // Only do-the-do if there's a valid field ID
     778                if ( ! empty( $r['field_id'] ) ) :
     779
     780                        // Start the output buffer
     781                        ob_start();
     782
     783                        // Output anything before
     784                        echo $r['before']; ?>
     785
     786                        <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?>
     787
     788                                <select class="<?php echo esc_attr( $r['class'] ); ?>" name="<?php echo esc_attr( 'field_' . $r['field_id'] ) ; ?>_visibility">
     789
     790                                        <?php foreach ( bp_xprofile_get_visibility_levels() as $level ) : ?>
     791
     792                                                <option value="<?php echo esc_attr( $level['id'] ); ?>" <?php selected( $level['id'], bp_get_the_profile_field_visibility_level() ); ?>><?php echo esc_html( $level['label'] ); ?></option>
     793
     794                                        <?php endforeach; ?>
     795
     796                                </select>
     797
     798                        <?php else : ?>
     799
     800                                <span class="field-visibility-settings-notoggle" title="<?php esc_attr_e( "This field's visibility cannot be changed.", 'buddypress' ); ?>"><?php bp_the_profile_field_visibility_level_label(); ?></span>
     801
     802                        <?php endif;
     803
     804                        // Output anything after
     805                        echo $r['after'];
     806
     807                        // Get the output buffer and empty it
     808                        $retval = ob_get_clean();
     809                endif;
    766810
    767811                // Output the dropdown list
    768                 return apply_filters( 'bp_xprofile_settings_visibility_select', ob_get_clean() );
    769         }
     812                return apply_filters( 'bp_profile_settings_visibility_select', $retval, $r, $args );
     813        }
Note: See TracChangeset for help on using the changeset viewer.