Advertisement
SergeyBiryukov

Delete Users Without Reassigning Posts

Feb 24th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Delete Users Without Reassigning Posts
  4. Plugin URI: http://ru.forums.wordpress.org/topic/45228
  5. Description: Allows you to delete any user on large installs, where reassigning posts to another user might be problematic.
  6. Author: Sergey Biryukov
  7. Author URI: http://profiles.wordpress.org/sergeybiryukov/
  8. Version: 0.1
  9. */
  10.  
  11. class Delete_Users_Without_Reassigning_Posts {
  12.  
  13.     function __construct() {
  14.         add_action( 'pre_user_query',         array( $this, 'disable_wp_dropdown_users' ) );
  15.         add_action( 'admin_footer-users.php', array( $this, 'hide_reassignment_option' ) );
  16.     }
  17.  
  18.     function disable_wp_dropdown_users( $user_query ) {
  19.         if ( ! is_admin() || 'users' !== get_current_screen()->id ) {
  20.             return;
  21.         }
  22.  
  23.         if ( ! isset( $_GET['action'] ) || 'delete' !== $_GET['action'] ) {
  24.             return;
  25.         }
  26.  
  27.         $user_query->query_where .= ' AND 1=0';
  28.     }
  29.  
  30.     function hide_reassignment_option() { ?>
  31.         <script>
  32.         jQuery(document).ready( function($) {
  33.             $( '#delete_option1' ).closest( 'li' ).hide();
  34.         });
  35.         </script>
  36.         <?php
  37.     }
  38.  
  39. }
  40.  
  41. new Delete_Users_Without_Reassigning_Posts;
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement