johnbillion / extended-cpts

A library which provides extended functionality to WordPress custom post types and taxonomies.
GNU General Public License v2.0
979 stars 96 forks source link

Add meta_format arg to admin col to allow formatting for display #114

Closed phlbnks closed 5 years ago

phlbnks commented 5 years ago

Full disclosure - I haven't run the tests or thought through potential security implications, but this is a feature missing compared to doing it manually. With the manual method you can have a "simple" column with a meta_value in it (so have sorting/filtering etc all work neatly), but use simple functions to affect display only such as ucfirst.

This adds a simply extra arg analgous to date_format called meta_format that is passed to call_use_func to be run on $val.

johnbillion commented 5 years ago

Thanks for the PR!

Does this provide much advantage over using the function argument for controlling the output of each field? https://github.com/johnbillion/extended-cpts/wiki/Admin-columns#custom-function

It seems like they're quite close in terms of functionality.

phlbnks commented 5 years ago

Gah - I should have tested this, sorry. From the docs I took it that using a custom function disabled column sorting (it does if you just copy the example to accomplish something like ucfirst). But actually it looks if you specify the meat_key as well, then you retain the nice sortable columns.

I suppose there could be some value in a meta_format as that implies that it is only for output styling of the meta_value rather than anything else, but since this can actually be accomplished with a custom function anyway that might just be bloat.

johnbillion commented 5 years ago

Good point, I'll update the docs to make it clearer that you can combine the function argument with the others.

I can see the value of a meta_format argument (and maybe even a term_format argument), but I think once you get into customisation of output it's better to allow complete control via the function argument instead.

I'll close this PR and I'll get the docs updated with some better examples. Cheers.