WordPress.org

Ready to get started?Download WordPress

Forums

Links shortcode
[TIP] Showing file size (2 posts)

  1. ildario
    Member
    Posted 2 years ago #

    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[2])."/".strrev($partes[1])."/".strrev($partes[0]);
    			/*** 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.

    http://wordpress.org/extend/plugins/links-shortcode/

  2. Maarten Swemmer
    Member
    Plugin Author

    Posted 2 years ago #

    Hello ildario,

    This could be an interesting addition. I suspect however that filesize($caminho) is a server intensive function, since it has to access the file system on each pageview, or not, unless you use caching?

    Does it make sense to manually (or automatically) store the file size info in the Notes field and extract it from there? Perhaps in the format '<file size="" />'? That would even pave the way for an infinite number of possible optional fields. Just brainstorming at this point.

    In any case to implement this in the plugin it would need to be something optional.

    Interested to learn your ideas on this.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic