I’ve noticed that if I send an attachment via Messages, when the recipient clicks on it the platform opens it up in another browser window. This is pretty annoying sometimes and would prefer much better to have the attachments downloaded on click, instead of opened in browser.
Any way to have this done? I’ve tried with some custom script such as:
add_action(‘wp_footer’, ‘fix_message_attachments’);
function fix_message_attachments() {
?>
jQuery(document).ready(function($) {
var $attachmentLinks = $('.hp-message__attachments a');
if ($attachmentLinks.length > 0) {
$attachmentLinks.attr('download', '');
}
});
</script>
<?php
}
but failed to make it work. I’ve also found a thread stating this was introduced as a feature a while ago but couldn’t find a setting for it under Hivepress - Messages ( HivePress 1.7.1 )
Also, as a separate issue, it seems users are able to delete their messages despite the “Allow users to delete messages” option being unchecked. Any idea why?
Unfortunately, this feature isn’t available at the moment because there’s no reliable way to force downloads currently. We’ll work on improving this UX in future updates. The linked release note is about adding a download icon for image attachments (previously, there was just a square preview, and you couldn’t download your own attachment, this wasn’t related to Messages).
Regarding the option to delete messages, please make sure you’re testing as a regular user and not as an admin, because admins have unlimited rights. Users and vendors should not have the option to delete messages if this feature is disabled in the settings.
If force download functionality is crucial for your use case, you might want to consider reaching out to our verified experts for custom development: Customize your website | HivePress.
Update - I managed to create a fix for this. Maybe it benefits other as well:
add_action(‘wp_footer’, ‘force_download_attachments’);
function force_download_attachments() {
?>
jQuery(document).ready(function($) {
// Function to find image links in messages and force download
function enforceDownload() {
// Target any link inside a message container
$('.hp-message a').each(function() {
var $link = $(this);
var href = $link.attr('href');
// Check if the link points to an image file (jpeg, jpg, gif, png)
if (href && href.match(/\.(jpeg|jpg|gif|png)$/i)) {
// Add the HTML5 download attribute to force saving the file
$link.attr('download', '');
}
});
}
// 1. Run immediately on page load for existing messages
enforceDownload();
// 2. Run automatically every time HivePress loads new messages via AJAX
$(document).ajaxComplete(function() {
enforceDownload();
});
});
</script>
<?php
}