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 have a very basic text widget, all it does is link to a PHP script which displays a random banner image. I would like to restrict viewing access to admins whilst I'm testing the widget. How is this possible? Can I use a WP function to restrict access to this widget?

share|improve this question

Simply add the following on top of your code:

if ( ! current_user_can( 'manage_options' ) );
share|improve this answer
All it does is stop the randomiser script working, which makes the image link broken. I've tried that before. I'd like to be able to hide the entire widget. – Ambo100 Jun 26 '11 at 16:29
"All it does is": aborts if the current user doesn't have the capability of manage_options which is assigned to admins per default. If your link (wherever this comes from - you showed no code) is broken, then you should place the above code somewhere else: exactly where you need to abort. – kaiser Jun 26 '11 at 17:07
I need to stop the widget from being displayed – Ambo100 Jun 26 '11 at 17:24
To make this clear: I can't guess what your exact code is. I showed you the possibilty to abort if a requirement wasn't met. Where you place this is now up to you. "I need to stop the widget from being displayed" sadly is no help. Post your code/Update your Q or try/error until it works. – kaiser Jun 26 '11 at 18:58

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.