WordPress.org

Make WordPress Core

Ticket #6405: 6405.diff

File 6405.diff, 4.2 KB (added by wojtek.szkutnik, 4 years ago)
  • wp-admin/users.php

     
    168168<ul> 
    169169<?php 
    170170        $go_delete = false; 
     171        $have_posts = false; 
     172                 
    171173        foreach ( (array) $userids as $id ) { 
    172174                $id = (int) $id; 
    173175                $user = new WP_User($id); 
     
    178180                        $go_delete = true; 
    179181                } 
    180182        } 
     183         
     184        if( $go_delete && have_many_users_links( $userids ) && have_many_users_posts( $userids ) )  
     185                $have_posts = true; 
     186                 
    181187        // @todo Delete is always for !is_multisite(). Use API. 
    182188        if ( !is_multisite() ) { 
    183189                $all_logins = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users ORDER BY user_login"); 
     
    193199        ?> 
    194200        </ul> 
    195201<?php if ( $go_delete ) : ?> 
     202<?php if ( $have_posts ) : ?> 
    196203        <fieldset><p><legend><?php _e('What should be done with posts and links owned by this user?'); ?></legend></p> 
    197204        <ul style="list-style:none;"> 
    198205                <li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" checked="checked" /> 
     
    200207                <li><input type="radio" id="delete_option1" name="delete_option" value="reassign" /> 
    201208                <?php echo '<label for="delete_option1">'.__('Attribute all posts and links to:')."</label> $user_dropdown"; ?></li> 
    202209        </ul></fieldset> 
     210<?php else : ?> 
     211 <input type="hidden" name="delete_option" value="delete" />    
     212<?php endif; ?> 
    203213        <input type="hidden" name="action" value="dodelete" /> 
    204214        <p class="submit"><input type="submit" name="submit" value="<?php esc_attr_e('Confirm Deletion'); ?>" class="button-secondary" /></p> 
    205215<?php else : ?> 
     
    274284<ul> 
    275285<?php 
    276286        $go_remove = false; 
    277         foreach ( $userids as $id ) { 
     287 
     288        foreach ( (array) $userids as $id ) { 
    278289                $id = (int) $id; 
    279290                $user = new WP_User($id); 
    280291                if ( $id == $current_user->id && !is_super_admin() ) { 
     
    286297                        $go_remove = true; 
    287298                } 
    288299        } 
     300                 
     301         
    289302        ?> 
    290303<?php if ( $go_remove ) : ?> 
    291304                <input type="hidden" name="action" value="doremove" /> 
  • wp-includes/user.php

     
    189189} 
    190190 
    191191/** 
     192 * Checks if user has written any posts 
     193 * 
     194 * @uses $wpdb WordPress database object for queries. 
     195 * 
     196 * @param int $userid User ID. 
     197 * @return bool False if no posts have been found, true otherwise 
     198 */ 
     199function has_user_posts($userid) { 
     200        global $wpdb; 
     201        $userid = (int) $userid; 
     202        $where = get_posts_by_author_sql('post', TRUE, $userid); 
     203        $count = $wpdb->get_var( "SELECT post_author FROM $wpdb->posts $where LIMIT 1", $userid ); 
     204        return $count ? true : false; 
     205} 
     206 
     207/** 
     208 * Checks if users have written any posts 
     209 * 
     210 * @param array $userid User ID number list. 
     211 * @return bool False if no posts have been found, true otherwise 
     212 */ 
     213function have_many_users_posts($users) { 
     214        global $wpdb; 
     215        if ( ! is_array($users) || empty( $users ) ) 
     216                return false; 
     217        $userlist = implode( ',', $users ); 
     218        $where = get_posts_by_author_sql( 'post' ); 
     219        $result = $wpdb->get_results( "SELECT post_author FROM $wpdb->posts $where AND post_author IN ($userlist) LIMIT 1", ARRAY_N ); 
     220        return $result ? true : false; 
     221} 
     222 
     223/** 
     224 * Checks if user has added any links 
     225 * 
     226 * @uses $wpdb WordPress database object for queries. 
     227 * 
     228 * @param int $userid User ID. 
     229 * @return bool False if no links have been found, true otherwise 
     230 */ 
     231function has_user_links($userid) { 
     232        global $wpdb; 
     233        $userid = (int) $userid; 
     234        $count = $wpdb->get_var( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d LIMIT 1", $userid ); 
     235        return $count ? true : false; 
     236} 
     237 
     238/** 
     239 * Checks if users have added any links 
     240 * 
     241 * @param array $userid User ID number list. 
     242 * @return bool False if no links have been found, true otherwise 
     243 */ 
     244function have_many_users_links($users) { 
     245        global $wpdb; 
     246        if ( ! is_array($users) || empty( $users ) ) 
     247                return false; 
     248        $userlist = implode( ',', $users ); 
     249        $result = $wpdb->get_results( "SELECT link_owner FROM $wpdb->links WHERE link_owner IN ($userlist) LIMIT 1", ARRAY_N ); 
     250        return $result ? true : false; 
     251} 
     252 
     253/** 
    192254 * Check that the user login name and password is correct. 
    193255 * 
    194256 * @since 0.71