Skip to:
Content

BuddyPress.org

Ticket #8321: 8321.patch

File 8321.patch, 5.5 KB (added by oztaser, 6 years ago)
  • src/bp-xprofile/bp-xprofile-admin.php

     
    6969                'add_field',
    7070                'edit_field',
    7171                'delete_field',
     72                'do_delete_field',
    7273                'delete_option'
    7374        );
    7475
    … …  
    9697                        }
    9798
    9899                // Delete field.
    99                 } elseif ( ( false !== $field_id ) && ( 'delete_field' === $mode ) ) {
    100                         xprofile_admin_delete_field( $field_id, 'field');
     100                } elseif ( ( false !== $field_id ) && ( in_array( $mode, array( 'delete_field', 'do_delete_field' ), true ) ) ) {
     101                        xprofile_admin_delete_field( $field_id, 'field' );
    101102
    102103                // Delete option.
    103104                } elseif ( ! empty( $option_id ) && 'delete_option' === $mode ) {
    … …  
    610611
    611612        check_admin_referer( 'bp_xprofile_delete_field-' . $field_id, 'bp_xprofile_delete_field' );
    612613
     614        $mode = ! empty( $_GET['mode'] ) ? sanitize_key( $_GET['mode'] ) : false;
     615
    613616        // Switch type to 'option' if type is not 'field'.
    614617        // @todo trust this param.
    615618        $field_type  = ( 'field' == $field_type ) ? __( 'field', 'buddypress' ) : __( 'option', 'buddypress' );
    616         $field       = xprofile_get_field( $field_id );
    617619
    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        // Display the field delete confirmation screen.
     621        if ( 'delete_field' === $mode ) {
     622                xprofile_admin_delete_field_screen( $field_id, $field_type );
     623
     624        // Handle the deletion of field
    622625        } else {
    623                 /* translators: %s: the field type */
    624                 $message = sprintf( __( 'The %s was deleted successfully!', 'buddypress' ), $field_type );
    625                 $type    = 'success';
     626                $field = xprofile_get_field( $field_id );
    626627
    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 );
     628                if ( !$field->delete( (bool) $delete_data ) ) {
     629                        /* translators: %s: the field type */
     630                        $message = sprintf( __( 'There was an error deleting the %s. Please try again.', 'buddypress' ), $field_type );
     631                        $type    = 'error';
     632                } else {
     633                        /* translators: %s: the field type */
     634                        $message = sprintf( __( 'The %s was deleted successfully!', 'buddypress' ), $field_type );
     635                        $type    = 'success';
     636
     637                        /**
     638                         * Fires at the end of the field deletion process, if successful.
     639                         *
     640                         * @since 1.0.0
     641                         *
     642                         * @param BP_XProfile_Field $field Current BP_XProfile_Field object.
     643                         */
     644                        do_action( 'xprofile_fields_deleted_field', $field );
     645                }
     646
     647                xprofile_admin_screen( $message, $type );
    635648        }
     649}
    636650
    637         xprofile_admin_screen( $message, $type );
     651/**
     652 * Display the delete confirmation screen of xprofile field.
     653 *
     654 * @since 7.0.0
     655 */
     656function xprofile_admin_delete_field_screen( $field_id, $field_type ) {
     657        if ( ! bp_current_user_can( 'bp_moderate' ) ) {
     658                die( '-1' );
     659        }
     660
     661        $field = xprofile_get_field( $field_id );
     662
     663        $base_url = remove_query_arg( array( 'mode', 'field_id', 'bp_xprofile_delete_field' ), $_SERVER['REQUEST_URI'] ); ?>
     664
     665        <div class="wrap">
     666                <h1><?php esc_html_e( sprintf ( 'Delete %s', $field_type ), 'buddypress' ) ?></h1>
     667                <p><?php esc_html_e( sprintf( 'You are about to delete the following %s:', $field_type ), 'buddypress' ) ?></p>
     668
     669                <ul class="bp-xprofile-delete-group-list">
     670                        <li><?php echo esc_html( $field->name ); ?></li>
     671                </ul>
     672
     673                <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p>
     674
     675                <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>
     676                <a class="button" href="<?php echo esc_attr( $base_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ) ?></a>
     677        </div>
     678
     679        <?php
    638680}
    639681
     682
     683
    640684/**
    641685 * Handles the ajax reordering of fields within a group.
    642686 *
  • src/bp-xprofile/classes/class-bp-xprofile-field.php

     
    13311331                        'page' => 'bp-profile-setup'
    13321332                ), $users_url );
    13331333
     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                }
    13341343                /**
    13351344                 * Fires before XProfile Field submit metabox.
    13361345                 *
    … …  
    13681377                                                <?php endif; ?>
    13691378
    13701379                                                <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>
    13721385                                                </div>
    13731386
    13741387                                                <?php wp_nonce_field( 'xprofile_delete_option' ); ?>