Changeset 5598
- Timestamp:
- 12/24/2011 06:01:22 PM (13 years ago)
- Location:
- trunk/bp-xprofile
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile/bp-xprofile-admin.php
r5452 r5598 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 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 */ 325 function xprofile_admin_delete_field( $field_id, $field_type = 'field', $delete_data = false ) { 321 326 global $message, $type; 322 327 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' ); 327 331 328 332 $field = new BP_XProfile_Field( $field_id ); 329 333 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'; 333 337 } 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'; 336 340 337 341 do_action( 'xprofile_fields_deleted_field', $field ); … … 460 464 461 465 <?php } ?> 466 467 <?php if ( $field->description ) : ?> 468 469 <p class="description"><?php echo esc_attr( $field->description ); ?></p> 470 471 <?php endif; ?> 472 462 473 <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; ?>464 474 <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> 475 476 <?php if ( $field->can_delete ) : ?> 477 478 <a class="submit-delete deletion" href="admin.php?page=bp-profile-setup&field_id=<?php echo esc_attr( $field->id ); ?>&mode=delete_field"><?php _e( 'Delete', 'buddypress' ); ?></a> 479 480 <?php endif; ?> 465 481 </div> 466 467 <?php if ( $field->description ) : ?>468 469 <p class="description"><?php echo esc_attr( $field->description ); ?></p>470 471 <?php endif; ?>472 473 482 </div> 474 483 </fieldset> -
trunk/bp-xprofile/bp-xprofile-classes.php
r5489 r5598 374 374 } 375 375 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 ) ) 384 383 return false; 385 384 … … 387 386 return false; 388 387 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 ); 391 391 392 392 return true;
Note: See TracChangeset
for help on using the changeset viewer.