Wednesday, 15 April 2015

admin - restrict wordpress user to only edit users with same meta key value -



admin - restrict wordpress user to only edit users with same meta key value -

i have wordpress site set up, within there master admin, have user role manager alter subscriber role able add together new users. have restricted subscriber making new users new role have created "player".

i have added custom field each user called "game". subscriber can alter , "player"' custom field. player cannot alter value.

i need alter "all users" page when subscriber signs in, show list of users have same cutom field value "game".

i have tried sorts of different plugins , tried own dablle @ changing code nil has worked :(

any help appreciated

andy

got code q&a, remove ability other users view administrator in user list?.

you need tweak bit adapt roles , capabilities, much changing meta_key , meta_value values. i've added check $pagenow sure fire in /wp-admin/users.php.

add_action( 'pre_user_query', 'filter_users_wpse_10742' ); function filter_users_wpse_10742( $user_search ) { global $pagenow; if( 'users.php' != $pagenow) return; $user = wp_get_current_user(); if ( $user->roles[0] != 'administrator' ) { global $wpdb; $user_search->query_where = str_replace('where 1=1', "where 1=1 , {$wpdb->users}.id in ( select {$wpdb->usermeta}.user_id $wpdb->usermeta {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}user_level' , {$wpdb->usermeta}.meta_value != 10)", $user_search->query_where ); } }

wordpress admin user-roles

No comments:

Post a Comment