Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/24/2011 06:01:22 PM (10 years ago)
Author:
johnjamesjacoby
Message:

When deleting a field, do not delete the field data by default. Fixes #3888. In memory of jimgroom's lost data.

File:
1 edited

Legend:

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

    r5452 r5598  
    313313}
    314314
    315 /**************************************************************************
    316  xprofile_admin_delete_field()
    317 
    318  Handles the deletion of a profile field [or option].
    319 **************************************************************************/
    320 function xprofile_admin_delete_field( $field_id, $type = 'field' ) {
     315/**
     316 * Handles the deletion of a profile field (or field option)
     317 *
     318 * @since BuddyPress (1.0)
     319 * @global string $message The feedback message to show
     320 * @global $type The type of feedback message to show
     321 * @param int $field_id The field to delete
     322 * @param string $field_type The type of field being deleted
     323 * @param bool $delete_data Should the field data be deleted too?
     324 */
     325function xprofile_admin_delete_field( $field_id, $field_type = 'field', $delete_data = false ) {
    321326    global $message, $type;
    322327
    323     if ( 'field' == $type )
    324         $type = __('field', 'buddypress');
    325     else
    326         $type = __('option', 'buddypress');
     328    // Switch type to 'option' if type is not 'field'
     329    // @todo trust this param
     330    $field_type  = ( 'field' == $field_type ) ? __( 'field', 'buddypress' ) : __( 'option', 'buddypress' );
    327331
    328332    $field = new BP_XProfile_Field( $field_id );
    329333
    330     if ( !$field->delete() ) {
    331         $message = sprintf( __('There was an error deleting the %s. Please try again', 'buddypress' ), $type );
    332         $type = 'error';
     334    if ( !$field->delete( (bool) $delete_data ) ) {
     335        $message = sprintf( __( 'There was an error deleting the %s. Please try again', 'buddypress' ), $field_type );
     336        $type    = 'error';
    333337    } else {
    334         $message = sprintf( __('The %s was deleted successfully!', 'buddypress' ), $type );
    335         $type = 'success';
     338        $message = sprintf( __( 'The %s was deleted successfully!', 'buddypress' ), $field_type );
     339        $type    = 'success';
    336340
    337341        do_action( 'xprofile_fields_deleted_field', $field );
     
    460464
    461465<?php } ?>
     466
     467<?php if ( $field->description ) : ?>
     468
     469                                <p class="description"><?php echo esc_attr( $field->description ); ?></p>
     470
     471<?php endif; ?>
     472
    462473                                <div class="actions">
    463                                     <?php if ( !$field->can_delete ) : ?>&nbsp;<?php else : ?><a class="submit-delete deletion ajax-option-delete" href="admin.php?page=bp-profile-setup&amp;field_id=<?php echo esc_attr( $field->id ); ?>&amp;mode=delete_field"><?php _e( 'Delete', 'buddypress' ); ?></a><?php endif; ?>
    464474                                    <a class="button edit" href="admin.php?page=bp-profile-setup&amp;group_id=<?php echo esc_attr( $admin_group->id ); ?>&amp;field_id=<?php echo esc_attr( $field->id ); ?>&amp;mode=edit_field"><?php _e( 'Edit', 'buddypress' ); ?></a>
     475
     476                                    <?php if ( $field->can_delete ) : ?>
     477
     478                                        <a class="submit-delete deletion" href="admin.php?page=bp-profile-setup&amp;field_id=<?php echo esc_attr( $field->id ); ?>&amp;mode=delete_field"><?php _e( 'Delete', 'buddypress' ); ?></a>
     479
     480                                    <?php endif; ?>
    465481                                </div>
    466 
    467 <?php if ( $field->description ) : ?>
    468 
    469                                 <p class="description"><?php echo esc_attr( $field->description ); ?></p>
    470 
    471 <?php endif; ?>
    472 
    473482                            </div>
    474483                        </fieldset>
Note: See TracChangeset for help on using the changeset viewer.