Ticket #3888: 3888-1.patch
File 3888-1.patch, 4.8 KB (added by , 13 years ago) |
---|
-
bp-xprofile/bp-xprofile-admin.php
47 47 else if ( isset( $_GET['mode'] ) && isset( $_GET['group_id'] ) && isset( $_GET['field_id'] ) && 'edit_field' == $_GET['mode'] ) 48 48 xprofile_admin_manage_field( $_GET['group_id'], $_GET['field_id'] ); 49 49 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' ); 52 52 53 53 else if ( isset( $_GET['mode'] ) && isset( $_GET['option_id'] ) && 'delete_option' == $_GET['mode'] ) 54 54 xprofile_admin_delete_field( $_GET['option_id'], 'option' ); … … 312 312 } 313 313 } 314 314 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 */ 323 function xprofile_admin_delete_field( $field_id, $type = 'field', $data_status = 'preserve_data' ) { 321 324 global $message, $type; 322 325 323 326 if ( 'field' == $type ) … … 327 330 328 331 $field = new BP_XProfile_Field( $field_id ); 329 332 330 if ( ! $field->delete() ) {333 if ( ! $field->delete( $data_status ) ) { 331 334 $message = sprintf( __('There was an error deleting the %s. Please try again', 'buddypress' ), $type ); 332 335 $type = 'error'; 333 336 } else { … … 460 463 461 464 <?php } ?> 462 465 <div class="actions"> 463 <?php if ( !$field->can_delete ) : ?> <?php else : ?><a class="submit-delete deletion ajax-option-delete " href="admin.php?page=bp-profile-setup&field_id=<?php echo esc_attr( $field->id ); ?>&mode=delete_field"><?php _e( 'Delete', 'buddypress' ); ?></a><?php endif; ?>466 <?php if ( !$field->can_delete ) : ?> <?php else : ?><a class="submit-delete deletion ajax-option-delete keep-data" href="admin.php?page=bp-profile-setup&field_id=<?php echo esc_attr( $field->id ); ?>&mode=delete_field"><?php _e( 'Delete Field', 'buddypress' ); ?></a><a class="submit-delete deletion ajax-option-delete" href="admin.php?page=bp-profile-setup&field_id=<?php echo esc_attr( $field->id ); ?>&mode=delete_field_and_data"><?php _e( 'Delete Field & Data', 'buddypress' ); ?></a><?php endif; ?> 464 467 <a class="button edit" href="admin.php?page=bp-profile-setup&group_id=<?php echo esc_attr( $admin_group->id ); ?>&field_id=<?php echo esc_attr( $field->id ); ?>&mode=edit_field"><?php _e( 'Edit', 'buddypress' ); ?></a> 465 468 </div> 466 469 -
bp-xprofile/bp-xprofile-classes.php
336 336 var $message = null; 337 337 var $message_type = 'err'; 338 338 339 function bp_xprofile_field( $id = null, $user_id = null, $get_data = true ) {340 $this->__construct( $id, $user_id, $get_data );341 }342 343 339 function __construct( $id = null, $user_id = null, $get_data = true ) { 344 340 if ( $id ) 345 341 $this->populate( $id, $user_id, $get_data ); … … 373 369 } 374 370 } 375 371 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' ) { 377 385 global $wpdb, $bp; 378 386 379 387 if ( !$this->id || … … 386 394 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE id = %d OR parent_id = %d", $this->id, $this->id ) ) ) 387 395 return false; 388 396 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 ); 391 400 392 401 return true; 393 402 }