You should do it with after_setup_theme
action:
function remove_inactive_widgets() {
$sidebars_widgets = get_option( 'sidebars_widgets' );
$sidebars_widgets['wp_inactive_widgets'] = array();
update_option( 'sidebars_widgets', $sidebars_widgets );
}
add_action( 'after_setup_theme', 'remove_inactive_widgets' );
Related Posts:
- Grabbing how Many Posts by Month for a Dashboard Widget
- Handling dozens of sidebars
- Widget Areas Still Appearing in WP ADMIN When They Shouldn’t
- Give Editor Access To Sidebar
- changing wp-admin/widgets.php
- Enabling jquery when dragging available widget to sidebar area
- Prevent widgets removal
- WordPress 4.8: Using multiple WYSIWYG-Editors with media inside of Widgets how to?
- How to Remove All Widgets from Dashboard?
- How do I save data from submitted form from widget
- How to listen to color changes on the color picker?
- Role that can edit only widgets, not other theme options
- Reorder dashboard widgets
- Ban certain widgets from certain sidebars
- Using tabs in admin widgets [closed]
- Completely disabling widgets
- Elegantly using JavaScript on widget admin forms
- Multiple users editting widgets
- dynamic_sidebar() returns false in admin section
- add_page_menu to make shortcut to widgets
- Widgets not expanding on wordpress 3.3 widget dashbord
- Remove/Add widgets from/to the Available Widgets pool
- jQuery UI inside widget on admin page
- How to get “Widget Logic” plugin’s input value in a custom widget code (to display on the Widget admin page)
- Add field to dashboard to update embedded URL on homepage?
- Dashboard Widgets – Add Admin Page With Same Functionality
- Drafts widget for admin page
- Validating widget’s configuration data on Admin page
- How to change color of registered widget areas in admin?
- Custom widget is not appearing in the admin area
- How to remove Help tab and the Dashboard widget area’s empty border
- Widget page stopped loading
- Adding a single text input field to a custom Dashboard widget
- How to change widget’s form color in admin?
- Issue with checked() echoing on to page
- Editing Help Section
- Allow users to give a dashboard widget a custom name using ACF
- How to customize WordPress dashboard for different users?
- Custom Admin Section
- Reposition the widget sidebar in Appearance->Widgets
- Widget stuck at particular point when dragging to bottom
- Creating an custom admin page for editing widgets
- jQuery “on” handler does not fire on newly inserted widgets [closed]
- Database size Widget
- Unable to add options on dashboard widget ?
- How to add the “page” post type to Recent Activity widget displayed in admin?
- How to obtain the user ID of the current profile being edited in WP-Admin?
- Get Widget Instance inside Widget
- How to Validate Widget Input
- When to use which plugin output method?
- Hooking Into Widget Output Loop
- Hide widget to non-logged in users without plugin (functions.php) [closed]
- WordPress: Apply filter/hook to a particular sidebar widgets?
- How can I add a new CSS class to a widget?
- wordpress widget textbox in the sidebar
- parse json object and display live in wordpress php widget
- How to get sidebar’s content inside admin-ajax?
- Run JS after widget settings are saved?
- Display the id list of active widgets of same sidebar?
- How to remove a widget from the sidebar on specific page?
- Where do I save widget code for wordpress?
- Is there any way to print a widget by having its id?
- Remove image height/width attributes from Image Widget
- Disable inline_edit() on edit.php
- Need help using a filter on the default Categories widget
- widget dropdown menu code
- custom widget does not saved value
- php to add a link into wp widget without specific url
- WordPress post feature image not uploading
- Widget Select Options not saving
- How to call widget by widget’s id?
- retain querystring values when savincustom options in admin
- How do widgets access posts they should display?
- Remove links from meta widget
- Can’t display custom widget
- How to make home widgets appear horizontally
- add_action not working within widget() of WP_Wdiget
- WordPress custom widget undefined variable notice
- Multiple rows of footer widget areas
- How do I make the title of the following widget editable?
- Escape HTML on WP input
- Publish page by invoking submit via jQuery
- Register new widget
- Newly created user role not displaying on users screen
- How to use register_sidebar’s ‘before_widget’ unique id generator into its other parameters like ‘before_title’?
- Set a dashboard widget to the top?
- How to decorate WP_Widget_Text?
- Siderbar implementation with collapsible bootstrap cards
- How to set selected attribute on option after filter query?
- Simple SCript Not Displayed in WIdth
- Conditionally Load a Script if a Certain Widget is Shown on a Page
- Where to add a widget class?
- Active Sidebar Conditional Question?
- Widget front-end fails to echo as expected from checkbox
- Help me tidy up my widget code
- Author Link in Recent Posts Widget
- Custom widget breaking widget section in admin menu
- Custom widgets do not appear in dashboard > appearance > widgets
- Can’t use is_home in template-functions.php
- How can I order the “Woocommerce Products Widget” by the sales date? [closed]