Skip to content

Instantly share code, notes, and snippets.

@norcross
Last active August 29, 2015 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norcross/e54978fe2a3f428b7217 to your computer and use it in GitHub Desktop.
Save norcross/e54978fe2a3f428b7217 to your computer and use it in GitHub Desktop.
modify user dropdown in delete page
<?php
function rkv_limit_users_delete( $query ) {
// first fetch the screen
$screen = get_current_screen();
// bail if we aren't on our user screen
if ( ! is_object( $screen ) || empty( $screen->base ) || ! empty( $screen->base ) && $screen->base != 'users' ) {
return $query;
}
// check that we are on our delete call
if ( ! isset( $_REQUEST['action'] ) || ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] != 'delete' ) {
return $query;
}
// get our current user
$user_id = get_current_user_id();
// call the global DB class
global $wpdb;
// modify our where clause to include the user ID
$query->query_where .= $wpdb->prepare( " AND $wpdb->users.ID = %d ", absint( $user_id ) );
// send it back
return $query;
}
add_filter( 'pre_user_query', 'rkv_limit_users_delete' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment