Skip to:
Content

BuddyPress.org

Changeset 13498


Ignore:
Timestamp:
06/07/2023 04:39:59 AM (18 months ago)
Author:
imath
Message:

xProfile: let the admin also remove data when deleting a field

Add a checkbox, active by default, informing deleting a field from the xProfile field Administration screen will also remove corresponding data. Opting out of this checkbox will let data in place.

Removing a deleted field corresponding data is improving Members search results consistency.

Props mike80222

Fixes #8864
Closes https://github.com/buddypress/buddypress/pull/114

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-admin.php

    r13491 r13498  
    100100        // Delete field.
    101101        } elseif ( ( false !== $field_id ) && ( in_array( $mode, array( 'delete_field', 'do_delete_field' ), true ) ) ) {
    102             xprofile_admin_delete_field( $field_id, 'field' );
     102            $delete_data = false;
     103            if ( isset( $_GET['delete_data'] ) && $_GET['delete_data'] ) {
     104                $delete_data = true;
     105            }
     106
     107            xprofile_admin_delete_field( $field_id, 'field', $delete_data );
    103108
    104109        // Delete option.
     
    791796    $field = xprofile_get_field( $field_id, null, false );
    792797
    793     $base_url = remove_query_arg( array( 'mode', 'field_id', 'bp_xprofile_delete_field' ), $_SERVER['REQUEST_URI'] ); ?>
     798    $base_url = remove_query_arg( array( 'page', 'mode', 'field_id', 'bp_xprofile_delete_field' ), $_SERVER['REQUEST_URI'] ); ?>
    794799
    795800    <div class="wrap">
     
    809814            <?php
    810815            printf(
    811                 /* translators: %s is the field type name. */
    812                 esc_html__( 'You are about to delete the following %s:', 'buddypress' ),
    813                 $field_type
     816                /* translators: 1 is the field type name. 2 is the field name */
     817                esc_html__( 'You are about to delete the following %1$s: %2$s.', 'buddypress' ),
     818                esc_html( $field_type ),
     819                '<strong>' . esc_html( $field->name ) . '</strong>'
    814820            );
    815821            ?>
    816822        </p>
    817823
    818         <ul class="bp-xprofile-delete-group-list">
    819             <li><?php echo esc_html( $field->name ); ?></li>
    820         </ul>
    821 
    822         <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ); ?></strong></p>
    823 
    824         <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>
    825         <a class="button" href="<?php echo esc_attr( $base_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ); ?></a>
     824        <form action="<?php echo esc_url( $base_url ); ?>" method="get">
     825            <label>
     826                <input type="checkbox" name="delete_data" value="1" <?php checked( true ); ?>/>
     827                <?php esc_html_e( 'Also remove the deleted field corresponding data.', 'buddypress' ); ?>
     828            </label>
     829            <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ); ?></strong></p>
     830            <p>
     831                <input type="hidden" name="page" value="bp-profile-setup" />
     832                <input type="hidden" name="mode" value="do_delete_field" />
     833                <input type="hidden" name="field_id" value="<?php echo esc_attr( $field_id ); ?>" />
     834                <?php
     835                wp_nonce_field( 'bp_xprofile_delete_field-' . $field_id, 'bp_xprofile_delete_field' );
     836                submit_button( __( 'Delete Permanently', 'buddypress' ), 'primary', '', false );
     837                ?>
     838                <a class="button" href="<?php echo esc_attr( $base_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ); ?></a>
     839            </p>
     840        </form>
    826841    </div>
    827 
    828842    <?php
    829843}
Note: See TracChangeset for help on using the changeset viewer.