Created
December 21, 2016 16:02
-
-
Save gareth-gillman/51823ef721bd7fdaac05449ad4a338a3 to your computer and use it in GitHub Desktop.
Show only shop managers to a shop manager in WP Admin users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('pre_user_query','yoursite_pre_user_query'); | |
function yoursite_pre_user_query($user_search) { | |
$roles = wp_get_current_user(); | |
if ( in_array( 'shop_manager', (array) $roles->roles ) ) { | |
global $wpdb; | |
$user_search->query_where = | |
str_replace('WHERE 1=1', | |
"WHERE 1=1 AND {$wpdb->users}.ID IN ( | |
SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta | |
WHERE {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}capabilities' | |
AND {$wpdb->usermeta}.meta_value LIKE '%shop_manager%')", | |
$user_search->query_where | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment