1

I have created two new roles in my theme, salesman and client. I want, when "salesman" is logged in to be able to view and edit only "client" users. I am trying this code (taken from an answer in this site)

add_action('pre_user_query','yoursite_pre_user_query');
function yoursite_pre_user_query($user_search) {
  $user = wp_get_current_user();

  if ($user->has_cap('salesman')) {
    global $wpdb;
    $user_search->query_where = str_replace(
        'WHERE 1=1',
      "WHERE 1=1 AND {$wpdb->users}.ID=6",$user_search->query_where);
  }
}

but actually, I can only filter (ID=6) using the ID of user. I want to change the code and make it like

  "WHERE 1=1 AND {$wpdb->users}.role='client'" <-----

but it doesnt work of course. Any idea how to solve this?

  • 1
    Tried user_role instead? – kaiser Sep 24 '13 at 0:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.