Code Duplication    Length = 19-22 lines in 2 locations

src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php 1 location

@@ 818-836 (lines=19) @@
815
816
		$request->set_param( 'context', 'edit' );
817
818
		if ( $force ) {
819
			$previous = $this->prepare_item_for_response( $comment, $request );
820
			$result = wp_delete_comment( $comment->comment_ID, true );
821
			$response = new WP_REST_Response();
822
			$response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
823
		} else {
824
			// If this type doesn't support trashing, error out.
825
			if ( ! $supports_trash ) {
826
				return new WP_Error( 'rest_trash_not_supported', __( 'The comment does not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
827
			}
828
829
			if ( 'trash' === $comment->comment_approved ) {
830
				return new WP_Error( 'rest_already_trashed', __( 'The comment has already been trashed.' ), array( 'status' => 410 ) );
831
			}
832
833
			$result = wp_trash_comment( $comment->comment_ID );
834
			$comment = get_comment( $comment->comment_ID );
835
			$response = $this->prepare_item_for_response( $comment, $request );
836
		}
837
838
		if ( ! $result ) {
839
			return new WP_Error( 'rest_cannot_delete', __( 'The comment cannot be deleted.' ), array( 'status' => 500 ) );

src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php 1 location

@@ 815-836 (lines=22) @@
812
813
814
		// If we're forcing, then delete permanently.
815
		if ( $force ) {
816
			$previous = $this->prepare_item_for_response( $post, $request );
817
			$result = wp_delete_post( $id, true );
818
			$response = new WP_REST_Response();
819
			$response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
820
		} else {
821
			// If we don't support trashing for this type, error out.
822
			if ( ! $supports_trash ) {
823
				return new WP_Error( 'rest_trash_not_supported', __( 'The post does not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
824
			}
825
826
			// Otherwise, only trash if we haven't already.
827
			if ( 'trash' === $post->post_status ) {
828
				return new WP_Error( 'rest_already_trashed', __( 'The post has already been deleted.' ), array( 'status' => 410 ) );
829
			}
830
831
			// (Note that internally this falls through to `wp_delete_post` if
832
			// the trash is disabled.)
833
			$result = wp_trash_post( $id );
834
			$post = get_post( $id );
835
			$response = $this->prepare_item_for_response( $post, $request );
836
		}
837
838
		if ( ! $result ) {
839
			return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) );