_wp_delete_orphaned_draft_menu_items

Deletes orphaned draft menu items.

Description

_wp_delete_orphaned_draft_menu_items(); 

Usage

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

Defined (1)

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

/wp-admin/includes/nav-menu.php  
  1. function _wp_delete_orphaned_draft_menu_items() { 
  2. global $wpdb; 
  3. $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); 
  4.  
  5. // Delete orphaned draft menu items. 
  6. $menu_items_to_delete = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp ) ); 
  7.  
  8. foreach ( (array) $menu_items_to_delete as $menu_item_id ) 
  9. wp_delete_post( $menu_item_id, true );