Make WordPress Core

Changeset 41131


Ignore:
Timestamp:
07/24/2017 10:40:12 PM (7 years ago)
Author:
johnbillion
Message:

Networks and Sites: Introduce an AYS when bulk deleting sites from the Sites screen in Network Admin.

Props flixos90, MaximeCulea

Fixes #41177

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/network/sites.php

    r39551 r41131  
    133133        break;
    134134
     135        case 'delete_sites':
     136            check_admin_referer( 'ms-delete-sites' );
     137
     138            foreach ( (array) $_POST['site_ids'] as $site_id ) {
     139                $site_id = (int) $site_id;
     140
     141                if ( $site_id == get_network()->site_id ) {
     142                    continue;
     143                }
     144
     145                if ( ! current_user_can( 'delete_site', $site_id ) ) {
     146                    $site = get_site( $site_id );
     147                    $site_address = untrailingslashit( $site->domain . $site->path );
     148
     149                    wp_die( sprintf( __( 'Sorry, you are not allowed to delete the site %s.' ), $site_address ), 403 );
     150                }
     151
     152                $updated_action = 'all_delete';
     153                wpmu_delete_blog( $site_id, true );
     154            }
     155            break;
     156
    135157        case 'allblogs':
    136158            if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
     
    141163                        switch ( $doaction ) {
    142164                            case 'delete':
    143                                 if ( ! current_user_can( 'delete_site', $val ) )
    144                                     wp_die( __( 'Sorry, you are not allowed to delete the site.' ) );
    145 
    146                                 $updated_action = 'all_delete';
    147                                 wpmu_delete_blog( $val, true );
     165                                require_once( ABSPATH . 'wp-admin/admin-header.php' );
     166                                ?>
     167                                <div class="wrap">
     168                                    <h1><?php _e( 'Confirm your action' ); ?></h1>
     169                                    <form action="sites.php?action=delete_sites" method="post">
     170                                        <input type="hidden" name="action" value="delete_sites" />
     171                                        <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
     172                                        <?php wp_nonce_field( 'ms-delete-sites', '_wpnonce', false ); ?>
     173                                        <p><?php _e( 'You are about to delete the following sites:' ); ?></p>
     174                                        <ul class="ul-disc">
     175                                            <?php foreach ( $_POST['allblogs'] as $site_id ) :
     176                                                $site = get_site( $site_id );
     177                                                $site_address = untrailingslashit( $site->domain . $site->path );
     178                                                ?>
     179                                                <li>
     180                                                    <?php echo $site_address; ?>
     181                                                    <input type="hidden" name="site_ids[]" value="<?php echo (int) $site_id; ?>" />
     182                                                </li>
     183                                            <?php endforeach; ?>
     184                                        </ul>
     185                                        <?php submit_button( __( 'Confirm' ), 'primary' ); ?>
     186                                    </form>
     187                                </div>
     188                                <?php
     189                                require_once( ABSPATH . 'wp-admin/admin-footer.php' );
     190                                exit();
    148191                            break;
    149192
Note: See TracChangeset for help on using the changeset viewer.