Skip to:
Content

BuddyPress.org

Changeset 5598


Ignore:
Timestamp:
12/24/2011 06:01:22 PM (13 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.

Location:
trunk/bp-xprofile
Files:
2 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>
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r5489 r5598  
    374374    }
    375375
    376     function delete() {
    377         global $wpdb, $bp;
    378 
    379         if ( !$this->id ||
    380             /* Prevent deletion by url when can_delete is false. */
    381             !$this->can_delete ||
    382             /* Prevent deletion of option 1 since this invalidates fields with options. */
    383             ( $this->parent_id && $this->option_order == 1 ) )
     376    function delete( $delete_data = false ) {
     377        global $wpdb, $bp;
     378
     379        // Prevent deletion if no ID is present
     380        // Prevent deletion by url when can_delete is false.
     381        // Prevent deletion of option 1 since this invalidates fields with options.
     382        if ( !$this->id || !$this->can_delete || ( $this->parent_id && $this->option_order == 1 ) )
    384383            return false;
    385384
     
    387386            return false;
    388387
    389         /* delete the data in the DB for this field */
    390         BP_XProfile_ProfileData::delete_for_field( $this->id );
     388        // delete the data in the DB for this field
     389        if ( true === $delete_data )
     390            BP_XProfile_ProfileData::delete_for_field( $this->id );
    391391
    392392        return true;
Note: See TracChangeset for help on using the changeset viewer.