Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
tom.myatt

Media Download Option

Hi there,

I’m using column sets to restrict options to specific user roles – great thus far!

What I’d like to expand to, is with one of the fields (custom fields) is a media upload from ACF.

I’ve set it so that I’m returning a Custom Field, with Field Type of ‘Media’ – with inline editing switched on. Would it be possible to have it so that instead of having to go to inline edit and paste in the attachment URL, that there’s a download media option available (perhaps wrapping the generated icon?)

Thanks

6 years, 2 months ago
Stefan van den Dungen Gronovius
Developer

Thanks for your feedback.
So do I understand you correctly that you want to wrap each image/media item in a link that allows you to download the media file directly to your computer?

We do have a similar behavior for the Custom Field, field type ‘Post’. For the field type, we have an extra option ‘Link To’ where you can select where to link to (edit post, view post, etc). We could do the same for media and add an extra option to download the media item. Does that sound like a solution for your request?

6 years, 2 months ago
tom.myatt

Hi Stefan,

Thanks for coming back to me.

I had a quick attempt at the above yesterday, the problem I’ve got though is that the Media Upload files are often containing confidential content that I only want internal admin to be able to access. For security reasons, we’ve redirected attachment pages to the related post and blocked (htaccess) the link to the upload URL.

So… I’m thinking I’m left with needing to write some custom code (functions.php, perhaps) that wraps the Icon with the file name and a path to the locally stored filename – is this something I can hook into with AC Pro?

6 years, 2 months ago
Stefan van den Dungen Gronovius
Developer

Sure we have a hook that you can use to alter the value of a column.

https://www.admincolumns.com/documentation/filter-reference/ac-column-value/

You could use the following snippet as a base and change it to your needs.

/**
 * @param $value  string
 * @param $id     int
 * @param $column AC_Column
 */
function acp_column_value_cf_media_download( $value, $id, $column ) {
	if ( $column instanceof ACP_Column_CustomField ) {
		$meta_key = $column->get_meta_key(); // This gets the Custom Field key
		$type = $column->get_field_type(); // This get the Custom Field field type

		// options: check for specific key in conditional
		if ( $column->get_empty_char() !== $value && 'library_id' === $type ) {
			$url = '#someurl'; // Get the redirected URL

			$value = sprintf( '<a href="%s" download="">%s</a>', $url, $value );
		}
	}

	return $value;
}

add_filter( 'ac/column/value', 'acp_column_value_cf_media_download', 10, 3 );
6 years, 2 months ago
tom.myatt

Thanks for this – hitting a bit of a wall with PHP knowledge though! Apologies if extending beyond scope of support / this forum…

If I set the field type to the standard ‘Attachment’ would it be possible to wrap the icon with a custom-ish URL? By default, it seems to return either a thumbnail or a count only…

Essentially I would need to get and replace the attachment URL with a different (sub) domain – file / upload path to remain the same….

e.g. ‘mysite.com/uploads/2015/02/testing.xls’ need to become ‘secure.mysite.com/uploads/2015/02/testing.xls’ and this gets wrapped around each attachment icon with a download attribute added…

6 years, 2 months ago
Stefan van den Dungen Gronovius
Developer

Sorry, I don’t understand what you mean by the default ‘Attachment’ field type. Do you mean the ACF field type? Or the field type in the custom field setting? We do have a media field type (like you mentioned before) but not an attachment type Anyway, this filter should work with any type so we just need the find the right solution for you.
Since we’re in the same timezone, please contact me on the live chat on our website so I can give you some live feedback.

6 years, 2 months ago

You must be logged in to reply to this topic.