boonebgorges / buddypress-docs

GNU General Public License v3.0
106 stars 44 forks source link

Documents auto downloading instead of opening in current tab or new tab #752

Open TAS1426 opened 2 months ago

TAS1426 commented 2 months ago

We are having an issue where documents are automatically downloading when clicked on, instead of opening in the current tab, or a new tab. Also, the URL of the document trying to download has "?bp-attachment=", and is a different URL than what is in our Media section.

boonebgorges commented 2 months ago

buddypress-docs changes URLs to the format ?bp-attachment= when the plugin detects that your installation supports "protection" mode. This generally means you're running Apache, and buddypress-docs has managed to set up the necessary rewrite rules. This feature is intended to provide protection against non-authorized access to attachments.

As for the direct download, in general this is the intended behavior for Doc attachments. But there's a feature that allows you to filter the headers, allowing the browser to open the file where possible. See https://github.com/boonebgorges/buddypress-docs/issues/659#issuecomment-521731262. See also #723.

TAS1426 commented 2 months ago

This is great. Thank you. It worked. One more question. Is there a way to have it open in a new tab that you're aware of?

boonebgorges commented 2 months ago

Something like this will probably work:

add_filter(
    'bp_docs_attachment_item_markup',
    function( $markup ) {
        $markup = str_replace( '<a ', '<a target="_blank" ', $markup );
        return $markup;
    }
);
TAS1426 commented 2 months ago

That worked. Thank you so much!