easy-digital-downloads icon indicating copy to clipboard operation
easy-digital-downloads copied to clipboard

Simplify edd_get_price_name

Open chriscct7 opened this issue 8 years ago • 2 comments

Made the function more safe by actually making sure $options has a price_id, not just an array of other details. Also removed the unneeded $name variable, and collapsed the logic of the if statement to a single line.

chriscct7 avatar Nov 05 '17 14:11 chriscct7

Been thinking about this lately. Should this be a method of EDD_Download? This helper can call the class, but this seems like something that belongs in the download object.

cklosowski avatar Nov 05 '17 14:11 cklosowski

No I don't think so, because a download object is an object of a complete download, not of a specific variation. What this function does doesn't make sense in the context of the download object. I think a helper function could be added called get_variation_name which takes in an index to return the name of.

However, loading an EDD Download object adds a ton of often unneeded DB calls. Every time we make some of these simpler functions do new EDD_Download and wrap them into that, we're causing functions to become a lot less performant than before, and particularly for simple, basic functions that will be used often in templating, that's not a really good practice.

chriscct7 avatar Nov 05 '17 17:11 chriscct7