WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the following widget


This allows me to restrict widgets using WP Conditional tags.

What I want is to restrict one widget to only 2 users.

This works for one user current_user_can('level_10') but gives access to all other level_10's (none atm) and not the other user.

How can I restrict this to just 2 users? I tried is_author( '4' ) but didn't seem to pick it up (think it's just for author pages)

share|improve this question
possible duplicate of How do I display a user specific content? – JMau Jul 23 '13 at 20:05
Your link is for a different plugin and does user roles, not specific users. I am looking for conditional code which works for 2 users who are different roles to work in the widget-logic plugin. – Cully Jul 23 '13 at 20:11
actually it does do specific users, but doesn't seem to work on widgets.. only posts or pages. – Cully Jul 23 '13 at 20:12
up vote 2 down vote accepted

I don't know the plugin, but with a rapid eye on it, it seems that what you want is not, but you can rely on widget_content filter fired by the plugin you are using.

So, in your theme function.php put:

if ( function_exists('widget_logic_redirected_callback') )
   add_filter('widget_content', 'my_widget_for_user', 10, 2);

function my_widget_for_users ($widget_content, $widget_id) {
   $allowed_users = array('username1', 'username2');
   $restricted_widgets = array('widget_id_1', 'widget_id_2');
   global $current_user;
   if ( in_array($widget_id, $restricted_widgets) && ( empty($current_user->user_login) || ! in_array($current_user->user_login, $allowed_users) ) ) {
      $widget_content = '';
   return $widget_content;

Doing so, if there is no user logged or the user is not an allowed one the widget is technically displayed but with no content so you will see... nothing.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.