Changeset 12676
- Timestamp:
- 07/02/2020 06:25:07 AM (3 years ago)
- Location:
- trunk/src/bp-xprofile
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/bp-xprofile-admin.php
r12668 r12676 70 70 'edit_field', 71 71 'delete_field', 72 'delete_option' 72 'do_delete_field', 73 'delete_option', 74 'do_delete_option' 73 75 ); 74 76 … … 97 99 98 100 // Delete field. 99 } elseif ( ( false !== $field_id ) && ( 'delete_field' === $mode) ) {100 xprofile_admin_delete_field( $field_id, 'field' );101 } elseif ( ( false !== $field_id ) && ( in_array( $mode, array( 'delete_field', 'do_delete_field' ), true ) ) ) { 102 xprofile_admin_delete_field( $field_id, 'field' ); 101 103 102 104 // Delete option. 103 } elseif ( ! empty( $option_id ) && 'delete_option' === $mode) {105 } elseif ( ! empty( $option_id ) && in_array( $mode, array( 'delete_option', 'do_delete_option' ), true ) ) { 104 106 xprofile_admin_delete_field( $option_id, 'option' ); 105 107 … … 611 613 check_admin_referer( 'bp_xprofile_delete_field-' . $field_id, 'bp_xprofile_delete_field' ); 612 614 615 $mode = ! empty( $_GET['mode'] ) ? sanitize_key( $_GET['mode'] ) : false; 616 613 617 // Switch type to 'option' if type is not 'field'. 614 618 // @todo trust this param. 615 619 $field_type = ( 'field' == $field_type ) ? __( 'field', 'buddypress' ) : __( 'option', 'buddypress' ); 616 $field = xprofile_get_field( $field_id ); 617 618 if ( !$field->delete( (bool) $delete_data) ) {619 /* translators: %s: the field type */620 $message = sprintf( __( 'There was an error deleting the %s. Please try again.', 'buddypress' ), $field_type ); 621 $type = 'error';620 621 // Display the field/option delete confirmation screen. 622 if ( in_array( $mode, array( 'delete_field', 'delete_option' ) ) ) { 623 xprofile_admin_delete_field_screen( $field_id, $field_type ); 624 625 // Handle the deletion of field 622 626 } else { 623 /* translators: %s: the field type */ 624 $message = sprintf( __( 'The %s was deleted successfully!', 'buddypress' ), $field_type ); 625 $type = 'success'; 626 627 /** 628 * Fires at the end of the field deletion process, if successful. 629 * 630 * @since 1.0.0 631 * 632 * @param BP_XProfile_Field $field Current BP_XProfile_Field object. 633 */ 634 do_action( 'xprofile_fields_deleted_field', $field ); 635 } 636 637 xprofile_admin_screen( $message, $type ); 638 } 627 $field = xprofile_get_field( $field_id ); 628 629 if ( !$field->delete( (bool) $delete_data ) ) { 630 /* translators: %s: the field type */ 631 $message = sprintf( __( 'There was an error deleting the %s. Please try again.', 'buddypress' ), $field_type ); 632 $type = 'error'; 633 } else { 634 /* translators: %s: the field type */ 635 $message = sprintf( __( 'The %s was deleted successfully!', 'buddypress' ), $field_type ); 636 $type = 'success'; 637 638 /** 639 * Fires at the end of the field deletion process, if successful. 640 * 641 * @since 1.0.0 642 * 643 * @param BP_XProfile_Field $field Current BP_XProfile_Field object. 644 */ 645 do_action( 'xprofile_fields_deleted_field', $field ); 646 } 647 648 xprofile_admin_screen( $message, $type ); 649 } 650 } 651 652 /** 653 * Display the delete confirmation screen of xprofile field/option. 654 * 655 * @since 7.0.0 656 */ 657 function xprofile_admin_delete_field_screen( $field_id, $field_type ) { 658 if ( ! bp_current_user_can( 'bp_moderate' ) ) { 659 die( '-1' ); 660 } 661 662 $field = xprofile_get_field( $field_id ); 663 664 $base_url = remove_query_arg( array( 'mode', 'field_id', 'bp_xprofile_delete_field' ), $_SERVER['REQUEST_URI'] ); ?> 665 666 <div class="wrap"> 667 <h1><?php printf( esc_html__( 'Delete %s', 'buddypress' ), $field_type ); ?></h1> 668 <p><?php printf( esc_html__( 'You are about to delete the following %s:', 'buddypress' ), $field_type ); ?></p> 669 670 <ul class="bp-xprofile-delete-group-list"> 671 <li><?php echo esc_html( $field->name ); ?></li> 672 </ul> 673 674 <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ); ?></strong></p> 675 676 <a class="button-primary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'mode' => 'do_delete_field', 'field_id' => $field_id ), $base_url ), 'bp_xprofile_delete_field-' . $field_id, 'bp_xprofile_delete_field' ) ); ?>"><?php esc_html_e( 'Delete Permanently', 'buddypress' ); ?></a> 677 <a class="button" href="<?php echo esc_attr( $base_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ); ?></a> 678 </div> 679 680 <?php 681 } 682 683 639 684 640 685 /** -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php
r12668 r12676 1332 1332 ), $users_url ); 1333 1333 1334 1335 // Delete. 1336 if ( $this->can_delete ) { 1337 $delete_url = wp_nonce_url( add_query_arg( array( 1338 'page' => 'bp-profile-setup', 1339 'mode' => 'delete_field', 1340 'field_id' => (int) $this->id 1341 ), $users_url ), 'bp_xprofile_delete_field-' . $this->id, 'bp_xprofile_delete_field' ); 1342 } 1334 1343 /** 1335 1344 * Fires before XProfile Field submit metabox. … … 1369 1378 1370 1379 <div id="delete-action"> 1371 <a href="<?php echo esc_url( $cancel_url ); ?>" class="deletion"><?php esc_html_e( 'Cancel', 'buddypress' ); ?></a> 1380 <?php if ( ! empty( $this->id ) && isset( $delete_url ) ) : ?> 1381 <a href="<?php echo esc_url( $delete_url ); ?>" class="submitdelete deletion"><?php esc_html_e( 'Delete', 'buddypress' ); ?></a> 1382 <?php endif; ?> 1383 1384 <div><a href="<?php echo esc_url( $cancel_url ); ?>" class="deletion"><?php esc_html_e( 'Cancel', 'buddypress' ); ?></a></div> 1372 1385 </div> 1373 1386
Note: See TracChangeset
for help on using the changeset viewer.