Forums Forums Search & Filter Pro How to remove the widget from the widget screen in admin?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Anonymous
    #60344

    I’d like to remove the Search & Filter Pro widget from the Available Widgets in the widget screen in the backend, to keep things simple for the content manager. I’ll be adding Search & Filter Pro to the site through a template, so I don’t need to have the widget available.

    I’ve removed many default WordPress widgets and a few from other plugins with my usual method: calling unregister_widget from the “widgets_init” action. This doesn’t seem to work for the Search & Filter widget. I’ve tried it using the widget base_id “search_filter_register_widget” at priorities 1, 10 and 100 but it doesn’t remove the widget. I can hide the widget with CSS, but that’s not ideal because it messes up the formatting of the other available widgets (they’re in two columns using floats on wider screens and it looks weird if I hide one with display:none).

    Can anyone tell me how to remove the Search & Filter widget from the widget screen? Thanks in advance.

    Trevor
    #60375

    Did it need to have caps:

    unregsiter_widget('Search_Filter_Register_Widget');
    
    Anonymous
    #60485

    I’ve tried that, but there’s no difference. Thanks for the suggestion though.

    This is the function I’m using:

    // Remove unwanted widgets
    function unregister_unwanted_widgets() {
      unregister_widget('WP_Widget_Pages');
      unregister_widget('WP_Widget_Calendar');
      unregister_widget('WP_Widget_Archives');
      ... (more unregister calls here) ...
      unregister_widget('Search_Filter_Register_Widget');
    }
    add_action('widgets_init', 'unregister_unwanted_widgets', 10);
    Trevor
    #60489

    Try using the older wp_unregister_sidebar_widget then

    Anonymous
    #60503

    That doesn’t work either unfortunately, when called from widgets_init anyway.

    Any chance you or anyone could try removing the widget in their own code to test what works?

    Trevor
    #60520

    I will need to refer this to the developer for advice. It may take a while for him to reply, as he is very busy.

    Ross Moderator
    #61525

    Hi there

    Can you try (in functions.php):

    add_action('widgets_init', 'init_widget');
    function init_widget()
    {
    	unregister_widget( 'Search_Filter_Register_Widget' );
    }
    

    I just realised the widget class is currently called Search_Filter_Register_Widget, I will be renaming this to Search_Filter_Widget in the next update, so you need both for future compatibility. Edit – Scratch that, we will leave it called Search_Filter_Register_Widget for now, changing it loses all users’ currently defined widgets!

    Thanks

    Anonymous
    #61552

    Thanks guys, I found the problem with your help. I was doing everything right (using the same code Ross suggests above), but I was running it from my own plugin. Apparently, this messes with the order of execution or something (despite having tried different priorities for the add_action call), because it did nothing. Adding it to functions.php though, works.

    Thank you for the support.

Viewing 8 posts - 1 through 8 (of 8 total)