Code Duplication    Length = 15-15 lines in 2 locations

includes/abstracts/abstract-wc-rest-posts-controller.php 1 location

@@ 443-457 (lines=15) @@
440
		// If we're forcing, then delete permanently.
441
		if ( $force ) {
442
			$result = wp_delete_post( $id, true );
443
		} else {
444
			// If we don't support trashing for this type, error out.
445
			if ( ! $supports_trash ) {
446
				return new WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( 'status' => 501 ) );
447
			}
448
449
			// Otherwise, only trash if we haven't already.
450
			if ( 'trash' === $post->post_status ) {
451
				return new WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 410 ) );
452
			}
453
454
			// (Note that internally this falls through to `wp_delete_post` if
455
			// the trash is disabled.)
456
			$result = wp_trash_post( $id );
457
		}
458
459
		if ( ! $result ) {
460
			return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) );

includes/api/class-wc-rest-products-controller.php 1 location

@@ 1784-1798 (lines=15) @@
1781
			}
1782
1783
			$result = wp_delete_post( $id, true );
1784
		} else {
1785
			// If we don't support trashing for this type, error out.
1786
			if ( ! $supports_trash ) {
1787
				return new WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( 'status' => 501 ) );
1788
			}
1789
1790
			// Otherwise, only trash if we haven't already.
1791
			if ( 'trash' === $post->post_status ) {
1792
				return new WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 410 ) );
1793
			}
1794
1795
			// (Note that internally this falls through to `wp_delete_post` if
1796
			// the trash is disabled.)
1797
			$result = wp_trash_post( $id );
1798
		}
1799
1800
		if ( ! $result ) {
1801
			return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) );