I'm looking for a way to restrict the ability to drag certain widgets to specific widget areas in the widget editor.

For example, I would like to restrict the widget field 'ads' to only be available to administrators. I would be quite happy if I could do this by disabling the ability to drag-n-drop in these fields.

Anyone got any ideas?

  • 1
    Wouldn't it be enough to simply not display it to other user roles?
    – kaiser
    Nov 4 '13 at 14:30
  • I ended up hiding the area to drop it in.
    – parse
    Nov 5 '13 at 7:42

I ended up adding the class 'ab-ads' to all my widget areas.

if ( !is_super_admin() ) {
  add_action('admin_print_styles-widgets.php', function() {
      echo '<style type="text/css">div.sidebar-widgets-ab-ads { display:none; }</style>';

That way I just hide them for everyone that isn't administrators.

  • If you got someone as a user, who knows how to use Chrome Dev Tools, FireBug, etc. then they will have full access. Not that cool, right?
    – kaiser
    Nov 5 '13 at 13:56
  • kaiser: True, but that won't be an issue in this setup.
    – parse
    Dec 3 '13 at 13:09

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.