Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

Simply add the following on top of your code:

if ( ! current_user_can( 'manage_options' ) );
    return;
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
2  
"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
1  
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

 
discard

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.