Custom data filters

I posted over at the showcase about a site I'd made with a modifed admin-functions.php. It was pointed out to me that I could have used filters without modifying the core - so I tried them out.

I'm customising the filter-custom_data.php plugin here. What I want to do is add 2 new custom fields (Price and Availability). Availability is a radio button with the values 'Sold' and 'For sale'.

With the function `custom_data_edit_album($discard, $album, $prefix)` is it possible to store multiple fields of custom data? It seems at the moment that you only have `$album->get('custom_data')` which stores one bit of data.

Also, can you use the filters to remove certain fields from the layout?

Comments

  • Multiple fields are (typically) stored by using serialize and unserialize on an array that is indexed by the fields. But of course you can use any means you want to indicate the separate items.

    I suggest you look at the `comment_form` plugin as an example. (It is attaching the `edit_admin_custom_data` and `save_admin_custom_data` filters, but the concept is the same.)

    You would be able to remove only those fields that are conditioned to be removed. For instance you could remove fields that another plugin was using custom data to implement.
Sign In or Register to comment.