@@ -447,29 +447,39 @@ public function get( $args, $assoc_args ) {
447447 * Success: Deleted post 1294.
448448 */
449449 public function delete ( $ args , $ assoc_args ) {
450- $ defaults = array (
451- 'force ' => false ,
452- );
450+ $ defaults = [ 'force ' => false ];
453451 $ assoc_args = array_merge ( $ defaults , $ assoc_args );
454452
455- parent ::_delete ( $ args , $ assoc_args , function ( $ post_id , $ assoc_args ) {
456- $ status = get_post_status ( $ post_id );
457- $ post_type = get_post_type ( $ post_id );
453+ parent ::_delete ( $ args , $ assoc_args , [ $ this , 'delete_callback ' ] );
454+ }
458455
459- if ( !$ assoc_args ['force ' ] && ( $ post_type !== 'post ' && $ post_type !== 'page ' ) ) {
460- return array ( 'error ' , "Posts of type ' $ post_type' do not support being sent to trash. \nPlease use the --force flag to skip trash and delete them permanently. " );
461- }
456+ /**
457+ * Callback used to delete a post.
458+ *
459+ * @param $post_id
460+ * @param $assoc_args
461+ * @return array
462+ */
463+ protected function delete_callback ( $ post_id , $ assoc_args ) {
464+ $ status = get_post_status ( $ post_id );
465+ $ post_type = get_post_type ( $ post_id );
466+
467+ if ( ! $ assoc_args ['force ' ]
468+ && ( $ post_type !== 'post ' && $ post_type !== 'page ' ) ) {
469+ return [
470+ 'error ' ,
471+ "Posts of type ' {$ post_type }' do not support being sent to trash. \n"
472+ . 'Please use the --force flag to skip trash and delete them permanently. ' ,
473+ ];
474+ }
462475
463- $ r = wp_delete_post ( $ post_id , $ assoc_args ['force ' ] );
476+ if ( ! wp_delete_post ( $ post_id , $ assoc_args ['force ' ] ) ) {
477+ return [ 'error ' , "Failed deleting post {$ post_id }. " ];
478+ }
464479
465- if ( $ r ) {
466- $ action = $ assoc_args ['force ' ] || 'trash ' === $ status || 'revision ' === $ post_type ? 'Deleted ' : 'Trashed ' ;
480+ $ action = $ assoc_args ['force ' ] || 'trash ' === $ status || 'revision ' === $ post_type ? 'Deleted ' : 'Trashed ' ;
467481
468- return array ( 'success ' , "$ action post $ post_id. " );
469- } else {
470- return array ( 'error ' , "Failed deleting post $ post_id. " );
471- }
472- } );
482+ return [ 'success ' , "{$ action } post {$ post_id }. " ];
473483 }
474484
475485 /**
0 commit comments