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?


Simply add the following on top of your code:

if ( ! current_user_can( 'manage_options' ) );
  • 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

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

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