public function delete_upload($force = true)
    {
        // Bail early if not uploaded.
        if ($this->get_upload_path() === null) {
            return false;
        }

        if ($this->get_id() !== null) {
            $result = !\wp_delete_attachment($this->get_id(), $force) === false;
        } else {
            \wp_delete_file($this->get_upload_path());
            $result = !\file_exists($this->get_upload_path());
        }

        if ($result === true) {
            $this->attachment_id = null;
            $this->upload_path = null;
            $this->upload_error = null;
            $this->upload_type = null;
            $this->upload_url = null;
        }

        return $result;
    }
public function delete_upload($force = true)
    {
        // Bail early if not uploaded.
        if ($this->get_upload_path() === null) {
            return false;
        }

        if ($this->get_id() !== null) {
            $result = !\wp_delete_attachment($this->get_id(), $force) === false;
        } else {
            \wp_delete_file($this->get_upload_path());
            $result = !\file_exists($this->get_upload_path());
        }

        if ($result === true) {
            $this->attachment_id = null;
            $this->upload_path = null;
            $this->upload_error = null;
            $this->upload_type = null;
            $this->upload_url = null;
        }

        return $result;
    }
public function delete_upload ( $ force = true ) { // Bail early if not uploaded. if ( $ this -> get_upload_path ( ) === null ) { return false ; } if ( $ this -> get_id ( ) !== null ) { $ result = ! \ wp_delete_attachment ( $ this -> get_id ( ) , $ force ) === false ; } else { \ wp_delete_file ( $ this -> get_upload_path ( ) ) ; $ result = ! \ file_exists ( $ this -> get_upload_path ( ) ) ; } if ( $ result === true ) { $ this -> attachment_id = null ; $ this -> upload_path = null ; $ this -> upload_error = null ; $ this -> upload_type = null ; $ this -> upload_url = null ; } return $ result ; }
Remove the uploaded version of the file, and delete from the media library if added.

@since 1.0.0

@param bool $force Skip trash and completely delete file and data.
@return bool
Remove the uploaded version of the file and delete from the media library if added .