wp_ajax_delete_inactive_widgets

Ajax handler for removing inactive widgets.

Description

wp_ajax_delete_inactive_widgets(); 

Usage

  1. if ( !function_exists( 'wp_ajax_delete_inactive_widgets' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_ajax_delete_inactive_widgets(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_delete_inactive_widgets() { 
  2. check_ajax_referer( 'remove-inactive-widgets', 'removeinactivewidgets' ); 
  3.  
  4. if ( ! current_user_can( 'edit_theme_options' ) ) { 
  5. wp_die( -1 ); 
  6.  
  7. unset( $_POST['removeinactivewidgets'], $_POST['action'] ); 
  8.  
  9.  
  10. $sidebars_widgets = wp_get_sidebars_widgets(); 
  11.  
  12. foreach ( $sidebars_widgets['wp_inactive_widgets'] as $key => $widget_id ) { 
  13. $pieces = explode( '-', $widget_id ); 
  14. $multi_number = array_pop( $pieces ); 
  15. $id_base = implode( '-', $pieces ); 
  16. $widget = get_option( 'widget_' . $id_base ); 
  17. unset( $widget[$multi_number] ); 
  18. update_option( 'widget_' . $id_base, $widget ); 
  19. unset( $sidebars_widgets['wp_inactive_widgets'][$key] ); 
  20.  
  21. wp_set_sidebars_widgets( $sidebars_widgets ); 
  22.  
  23. wp_die();