@@ -506,23 +506,24 @@ protected function delete_callback( $post_id, $assoc_args ) {
506506 $ status = get_post_status ( $ post_id );
507507 $ post_type = get_post_type ( $ post_id );
508508
509- if ( ! $ assoc_args ['force ' ]
510- && 'trash ' !== $ status
511- && ( 'post ' !== $ post_type && 'page ' !== $ post_type ) ) {
512- return [
513- 'error ' ,
514- "Posts of type ' {$ post_type }' do not support being sent to trash. \n"
515- . 'Please use the --force flag to skip trash and delete them permanently. ' ,
516- ];
517- }
509+ $ force_delete = $ assoc_args ['force ' ] || 'trash ' === $ status || 'revision ' === $ post_type ;
518510
519- if ( ! wp_delete_post ( $ post_id , $ assoc_args ['force ' ] ) ) {
520- return [ 'error ' , "Failed deleting post {$ post_id }. " ];
511+ if ( $ force_delete || ! EMPTY_TRASH_DAYS ) {
512+ if ( ! wp_delete_post ( $ post_id , true ) ) {
513+ return [ 'error ' , "Failed deleting post {$ post_id }. " ];
514+ }
515+
516+ return [ 'success ' , "Deleted post {$ post_id }. " ];
521517 }
522518
523- $ action = $ assoc_args ['force ' ] || 'trash ' === $ status || 'revision ' === $ post_type ? 'Deleted ' : 'Trashed ' ;
519+ // Use wp_trash_post() directly because wp_delete_post() only auto-trashes
520+ // 'post' and 'page' types, permanently deleting all other post types even
521+ // when $force_delete is false. wp_trash_post() works for all post types.
522+ if ( wp_trash_post ( $ post_id ) ) {
523+ return [ 'success ' , "Trashed post {$ post_id }. " ];
524+ }
524525
525- return [ 'success ' , "{ $ action } post {$ post_id }. " ];
526+ return [ 'error ' , "Failed trashing post {$ post_id }. " ];
526527 }
527528
528529 /**
0 commit comments