I've been harping about this forever now but don't think there is an open issue for tracking.
As EDD makes a push for more themes (Themedd!) and continued development of many extensions that output downloads for various reasons I think this becomes even more important. There are a few issues with the current way the [downloads] shortcode loads multiple template files.
[downloads] shortcode (not necessarily a bad thing) or call the edd_downloads_query() function directly to achieve the same output as their store page.In my mind this is the preferred approach that themes and plugins should be taking.
[downloads] shortcode has to either duplicate the code inside of edd_downloads_query() and then selectively include the separate template files. Often times this leaves out many of the filters that are in the shortcode callback, and if they do exist it's different so extra code still needs to be added.This has caused issues with current extensions that output lists of downloads completely differently than what a theme has styled for the shortcode.
e.g: https://github.com/easydigitaldownloads/edd-recommended-products/issues/15
edd_downloads_query() is massive and is certainly not just querying downloads.There are many pros to calling these multiple template files from a singular file:
The bad things:
edd_get_template_part() can't pass variables so the existing $atts array would need some finagling. My proposal would be to replace https://github.com/easydigitaldownloads/easy-digital-downloads/blob/master/includes/shortcodes.php#L564-L587 with an action that calls a template file. This will allow the $atts variable to be dealt with.
function edd_download_item( $atts ) {
global $atts;
edd_get_template_part( 'shortcode', 'download' );
}
add_action( 'edd_download_item', 'edd_download_item' );
<?php
/**
* A download for the [downloads] grid.
*/
global $atts;
https://github.com/easydigitaldownloads/easy-digital-downloads/blob/master/includes/shortcodes.php#L564-L587
So there are technically no immediate benefits for existing themes/plugins but it will certainly help things a lot moving forward.
Thoughts?
I support this 100%.
Great! I'll try to get a PR ready once 2.7 dev starts.
And the world rejoiced!
Should we have more specific variable names than $atts and $i as they are very generic and in the global scope?
@sunnyratilal yes please
This is working well for me
Left some notes on the PR.
Most helpful comment
I support this 100%.