bp_docs_delete_folder_contents

Delete folder contents.

Description

bp_docs_delete_folder_contents( (int) $folder_id ); 

Parameters (1)

0. $folder_id (int)
The folder id.

Usage

  1. if ( !function_exists( 'bp_docs_delete_folder_contents' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-docs/includes/addon-folders.php'; 
  3.  
  4. // The folder id. 
  5. $folder_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_docs_delete_folder_contents($folder_id); 
  9.  

Defined (1)

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

/includes/addon-folders.php  
  1. function bp_docs_delete_folder_contents( $folder_id ) { 
  2.  
  3. // Docs first 
  4. $folder_term = bp_docs_get_folder_term( $folder_id ); 
  5. $folder_docs = get_posts( array( 
  6. 'post_type' => bp_docs_get_post_type_name(),  
  7. 'tax_query' => array( 
  8. array( 
  9. 'taxonomy' => 'bp_docs_doc_in_folder',  
  10. 'field' => 'term_id',  
  11. 'terms' => $folder_term,  
  12. ),  
  13. ),  
  14. 'update_meta_cache' => false,  
  15. 'update_term_cache' => false,  
  16. ) ); 
  17.  
  18. $retval = true; 
  19.  
  20. foreach ( $folder_docs as $fd ) { 
  21. if ( ! wp_trash_post( $fd->ID ) ) { 
  22. $retval = false; 
  23.  
  24. // Subfolders 
  25. $folder_subfolders = bp_docs_get_folders( array( 
  26. 'parent_id' => $folder_id,  
  27. ) ); 
  28.  
  29. // Recurse 
  30. foreach ( $folder_subfolders as $fs ) { 
  31. $deleted_fs = bp_docs_delete_folder( array( 
  32. 'folder_id' => $fs->ID,  
  33. 'delete_contents' => true,  
  34. ) ); 
  35.  
  36. if ( ! $deleted_fs ) { 
  37. $retval = false; 
  38.  
  39. return $retval;