WordPress.org

Make WordPress Core

Changeset 34000


Ignore:
Timestamp:
09/10/2015 04:46:38 PM (4 years ago)
Author:
wonderboymusic
Message:

When deleting via User List Table, don't prompt for re-attribution if the user(s) do(es) not have any posts.

Props rajnikmit, wojtek.szkutnik, benjmay, wonderboymusic.
Fixes #6405.

Location:
trunk/src/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/user.php

    r33774 r34000  
    447447    echo '</p></div>';
    448448}
     449
     450/**
     451 * @since 3.5.0
     452 * @access private
     453 */
     454function delete_users_add_js() { ?>
     455<script>
     456jQuery(document).ready( function($) {
     457    var submit = $('#submit').prop('disabled', true);
     458    $('input[name="delete_option"]').one('change', function() {
     459        submit.prop('disabled', false);
     460    });
     461    $('#reassign_user').focus( function() {
     462        $('#delete_option1').prop('checked', true).trigger('change');
     463    });
     464});
     465</script>
     466<?php
     467}
  • trunk/src/wp-admin/users.php

    r33888 r34000  
    8181$update = '';
    8282
    83 /**
    84  * @since 3.5.0
    85  * @access private
    86  */
    87 function delete_users_add_js() { ?>
    88 <script>
    89 jQuery(document).ready( function($) {
    90     var submit = $('#submit').prop('disabled', true);
    91     $('input[name=delete_option]').one('change', function() {
    92         submit.prop('disabled', false);
    93     });
    94     $('#reassign_user').focus( function() {
    95         $('#delete_option1').prop('checked', true).trigger('change');
    96     });
    97 });
    98 </script>
    99 <?php
    100 }
    101 
    10283switch ( $wp_list_table->current_action() ) {
    10384
     
    216197        $userids = array_map( 'intval', (array) $_REQUEST['users'] );
    217198
    218     add_action( 'admin_head', 'delete_users_add_js' );
     199    $users_posts = new WP_Query( array(
     200        'post_type' => 'any',
     201        'author' => implode( ',', $userids ),
     202        'posts_per_page' => 1
     203    ) );
     204
     205    if ( $users_posts->have_posts() ) {
     206        add_action( 'admin_head', 'delete_users_add_js' );
     207    }
    219208
    220209    include( ABSPATH . 'wp-admin/admin-header.php' );
     
    252241    ?>
    253242    </ul>
    254 <?php if ( $go_delete ) : ?>
    255     <?php if ( 1 == $go_delete ) : ?>
    256         <fieldset><p><legend><?php _e( 'What should be done with content owned by this user?' ); ?></legend></p>
    257     <?php else : ?>
    258         <fieldset><p><legend><?php _e( 'What should be done with content owned by these users?' ); ?></legend></p>
    259     <?php endif; ?>
    260     <ul style="list-style:none;">
    261         <li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" />
    262         <?php _e('Delete all content.'); ?></label></li>
    263         <li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
    264         <?php echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
    265         wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li>
    266     </ul></fieldset>
    267     <?php
     243<?php if ( $go_delete ) :
     244
     245    if ( ! $users_posts->have_posts() ) : ?>
     246        <input type="hidden" name="delete_option" value="delete" />
     247    <?php else: ?>
     248        <?php if ( 1 == $go_delete ) : ?>
     249            <fieldset><p><legend><?php _e( 'What should be done with content owned by this user?' ); ?></legend></p>
     250        <?php else : ?>
     251            <fieldset><p><legend><?php _e( 'What should be done with content owned by these users?' ); ?></legend></p>
     252        <?php endif; ?>
     253        <ul style="list-style:none;">
     254            <li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" />
     255            <?php _e('Delete all content.'); ?></label></li>
     256            <li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
     257            <?php echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
     258            wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li>
     259        </ul></fieldset>
     260    <?php endif;
    268261    /**
    269262     * Fires at the end of the delete users form prior to the confirm button.
Note: See TracChangeset for help on using the changeset viewer.