Skip to:
Content

BuddyPress.org

Ticket #3888: 3888-1.patch

File 3888-1.patch, 4.8 KB (added by DJPaul, 12 years ago)
  • bp-xprofile/bp-xprofile-admin.php

     
    4747        else if ( isset( $_GET['mode'] ) && isset( $_GET['group_id'] ) && isset( $_GET['field_id'] ) && 'edit_field' == $_GET['mode'] )
    4848                xprofile_admin_manage_field( $_GET['group_id'], $_GET['field_id'] );
    4949
    50         else if ( isset( $_GET['mode'] ) && isset( $_GET['field_id'] ) && 'delete_field' == $_GET['mode'] )
    51                 xprofile_admin_delete_field( $_GET['field_id'], 'field');
     50        else if ( ( isset( $_GET['mode'] ) && isset( $_GET['field_id'] ) ) && ( 'delete_field' == $_GET['mode'] || 'delete_field_and_data' == $_GET['mode'] ) )
     51                xprofile_admin_delete_field( $_GET['field_id'], 'field', ( 'delete_field' == $_GET['mode'] ) ? 'preserve_data' : 'delete_data' );
    5252
    5353        else if ( isset( $_GET['mode'] ) && isset( $_GET['option_id'] ) && 'delete_option' == $_GET['mode'] )
    5454                xprofile_admin_delete_field( $_GET['option_id'], 'option' );
     
    312312        }
    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 option].
     317 *
     318 * @param int $field_id
     319 * @param string $type Optional
     320 * @param string $data_status Optional; controls if data is deleted when the field is deleted. Either "preserve_data" or "delete_data".
     321 * @since ?
     322 */
     323function xprofile_admin_delete_field( $field_id, $type = 'field', $data_status = 'preserve_data' ) {
    321324        global $message, $type;
    322325
    323326        if ( 'field' == $type )
     
    327330
    328331        $field = new BP_XProfile_Field( $field_id );
    329332
    330         if ( !$field->delete() ) {
     333        if ( ! $field->delete( $data_status ) ) {
    331334                $message = sprintf( __('There was an error deleting the %s. Please try again', 'buddypress' ), $type );
    332335                $type = 'error';
    333336        } else {
     
    460463
    461464<?php } ?>
    462465                                                                <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; ?>
     466                                                                        <?php if ( !$field->can_delete ) : ?>&nbsp;<?php else : ?><a class="submit-delete deletion ajax-option-delete keep-data" href="admin.php?page=bp-profile-setup&amp;field_id=<?php echo esc_attr( $field->id ); ?>&amp;mode=delete_field"><?php _e( 'Delete Field', 'buddypress' ); ?></a><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_and_data"><?php _e( 'Delete Field &amp; Data', 'buddypress' ); ?></a><?php endif; ?>
    464467                                                                        <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>
    465468                                                                </div>
    466469
  • bp-xprofile/bp-xprofile-classes.php

     
    336336        var $message = null;
    337337        var $message_type = 'err';
    338338
    339         function bp_xprofile_field( $id = null, $user_id = null, $get_data = true ) {
    340                 $this->__construct( $id, $user_id, $get_data );
    341         }
    342 
    343339        function __construct( $id = null, $user_id = null, $get_data = true ) {
    344340                if ( $id )
    345341                        $this->populate( $id, $user_id, $get_data );
     
    373369                }
    374370        }
    375371
    376         function delete() {
     372/**
     373*       xprofile_admin_delete_field( $_GET['field_id'], 'field', ( 'delete_field' == $_GET['mode'] ) ? 'preserve_data' : 'delete_data' );
     374*/
     375
     376        /**
     377         * Delete this profile field
     378         *
     379         * @global object $bp BuddyPress global settings
     380         * @global object $wp_query
     381         * @param string $data_status Optional; controls if data is deleted when the field is deleted. Either "preserve_data" or "delete_data".
     382         * @since ?
     383         */
     384        function delete( $data_status = 'preserve_data' ) {
    377385                global $wpdb, $bp;
    378386
    379387                if ( !$this->id ||
     
    386394                if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE id = %d OR parent_id = %d", $this->id, $this->id ) ) )
    387395                        return false;
    388396
    389                 /* delete the data in the DB for this field */
    390                 BP_XProfile_ProfileData::delete_for_field( $this->id );
     397                // Maybe delete the data in the DB for this field
     398                if ( 'delete_data' == $data_status )
     399                        BP_XProfile_ProfileData::delete_for_field( $this->id );
    391400
    392401                return true;
    393402        }