awesomemotive / easy-digital-downloads

Sell digital downloads through WordPress
https://easydigitaldownloads.com
GNU General Public License v2.0
864 stars 475 forks source link

Change "Downloads" Label Globally #168

Closed pippinsplugins closed 12 years ago

pippinsplugins commented 12 years ago

It might be nice if we setup a function with a filter that sets all of the default labels for "Downloads". These labels would be used in all of the widgets, all admin pages, etc. Right now we can change the regular post type labels, but nothing else.

Jason gave a nice list of all the places he'd like to change the labels here: http://easydigitaldownloads.com/forums/topic/payment-processing-issues/#post-1863

The filter would allow for someone (as Jason did) to easily change the labels to "Events", "Popular Events", "Latest Events", etc.

Thoughts @sksmatt ?

sksmatt commented 12 years ago

Maybe something like this? https://gist.github.com/2890536

Although I actually think that's a place for categories, as at the end these will all be downloads.

pippinsplugins commented 12 years ago

Yeah, I think that would work well. We'd then have to update all widgets and such to use those filters.

Do you think having this AND the posttype / taxonomy label filters makes it confusing?

sksmatt commented 12 years ago

I think we should keep it but pass the strings with placeholders like this: 'Add New %s' so then we can do sprintf and replace each with the already filtered labels we have:

https://gist.github.com/2890620

pippinsplugins commented 12 years ago

The one thing I'd add to that is apply_filters('edd_download_labels', $download_labels), just to make sure users can still change individual labels exactly as they want.

sksmatt commented 12 years ago

Definitely, It's actually there, but now moved to the first line:

$download_labels =  apply_filters('edd_download_labels', array( ...
pippinsplugins commented 12 years ago

The filter should be after the foreach, otherwise user's changes might get overwritten. Filters should almost always be last.

sksmatt commented 12 years ago

The plural and singular wildcard replacements can be changed on edd_get_default_labels():

apply_filters( 'edd_default_downloads_name', $defaults );

The rest of the string, the "Add New.." and the position of the wildcard is filterable on 'edd_download_labels'.

That way both can be changed and merged into one on the foreach.

pippinsplugins commented 12 years ago

But what if someone changed "add_new_item" to "Add New Stuff", while the default label was "Event" (not Stuff), would 'Stuff" get over written?

sksmatt commented 12 years ago

mm Ideally in this setup you would want to change 'Add New $1%s' to something like 'Insert another $1%s' rather than replacing the wildcard with another CPT name. That is why we would be giving the 'edd_default_downloads_name' filter.

This is a simple way to keep it both translatable and sort of dynamic, not sure if we could get away with a search and replace or something alike, would have to give more thought.

pippinsplugins commented 12 years ago

Hmm, okay, that's a good point.

pippinsplugins commented 12 years ago

I've tested the code as is and it doesn't quite work. Do you think you could do a little work on this in the next few days? I'd like to push out another update the first of the week, and hopefully include this in it, as there is a user waiting for it.

sksmatt commented 12 years ago

Sure I'll give it a second look, any hints on what didn't work?

pippinsplugins commented 12 years ago

Great. It wasn't correctly replacing 1$ and 2$ with the label, instead the labels were getting rendered with those place holders included.

sksmatt commented 12 years ago

Ha, I screwed the placeholder formatting, here goes a fixed update: https://gist.github.com/2890620

pippinsplugins commented 12 years ago

Great, works perfectly now!

If you could, please update the widget bundle at some point soon. The main things to update will be the widget titles (admin included).

sksmatt commented 12 years ago

I been thinking about this and realized we should instead use WordPress built-in functions without having to add new special behavior.

Take a look for example:

// get the download post type object
$downloads_obj = get_post_type_object( 'download' );
// return the menu name
$downloads_obj->labels->menu_name;

That could bring us the singular name or any other label we want.

I would suggest then, restoring the post-type.php file functions, and rather keep the singular, plurar functions we added but to retrieve the info in this other way:

/**
 * Get Label Singular
 *
 * @access      public
 * @since       1.0.8.4
 * @return      string
*/

function edd_get_label_singular() {
   $download_obj = get_post_type_object( 'download' );
   return $download_obj->labels->singular_name;
}

/**
 * Get Label Plural
 *
 * @access      public
 * @since       1.0.8.4
 * @return      string
*/

function edd_get_label_plural() {
   $download_obj = get_post_type_object( 'download' );
   return $download_obj->labels->name;
}

The custom post types file would go back to how it was before, and we would have these 2 functions as an extra to retrieve the labels easily on plugins or other sections.

pippinsplugins commented 12 years ago

Hmm, I can see good and bad things about this.

The good thing is that it makes sure that we keep everything more closely integrated with WP core.

The bad part is that it suddenly becomes harder for someone to adjust the labels. One of the good things about the new filter / functions is that a user can set two new labels (one for plural and one for singular), and everything changes. With this, the user would have to use the more advanced post type labels filter (which is probably fine).

Further thoughts?

sksmatt commented 12 years ago

Yeah, I follow what you mean. The alternative solution ( the first one ) is not a bad solution either, or far away from WP core. Let's roll like it this now and see If it's worth to change on the long run. Closing this till further discussion.