[Plugin: Links shortcode] [TIP] Showing file size
This tip is for a very specific use of this plugin.
Let’s say you’re using it to list files you’ve uploaded on wordpress media library and displaying links with Links Shortcode for download (PDFs, Docs, etc…).
In this case, it’s good to show the user the size of the file the user is about to download. In order to do it you can do this (i’ve hacked the v1.1) of this plugin on WP 3.4.1:
1- Open links-shortcode.php and after line 114, or after:
$linkinfo['link_url'] = $bm->link_url;
Paste this code:
/**File size **/ /** remove http ***/ $url = substr($bm->link_url, 7); /** revert url ***/ $url= strrev($url); /** split everything in parts ***/ $partes = explode("/", $url); /*** index the first 3 parts re-reverting ***/ $arquivo = "/".strrev($partes)."/".strrev($partes)."/".strrev($partes); /*** The upload directory **/ $uploads = wp_upload_dir(); /*** Compose the path ***/ $caminho = $uploads['basedir'].$arquivo; $docsize = @filesize($caminho); /*** size format is a built in WP function that shows the size in a nice format ***/ $linkinfo['link_size'] = '('.size_format($docsize).')'; /*** end**/
2- Now on the configuration screen you can use the [link_size] tag to show the size of a file you uploaded and linked. I know it’s a very specific case but maybe it can help someone.
- The topic ‘[Plugin: Links shortcode] [TIP] Showing file size’ is closed to new replies.