2011-08-08, 00:15:09
Carlos Wrote:What must a plugin do to insert its own field(s) to the customfields.xml file? Any recommended way?
Carlos Wrote:...or maybe I should have asked first:
Might plugins use CustomFields for their own fields?
Or is it better to leave that for user-created fields only, and keep adding the fields the usual way? (using changedata-save and edit-extras hooks)
Sorry for answering late - I was on vacation.
Assuming you are using the I18N Custom Filelds plugin:
- The fields in customfields.xml are displayed to the user, when he edits the page
- However, any other fields you add to a page during changedata-save can also be accessed using get/return_custom_field (e.g. the field creDate put there by the plugin itself.
- There is no function to write to customfields.xml - you have to read/modify/write the file yourself in your plugin (and check if the field is already there, ...)
- If you want to use a custom field in your plugin, you can ask the user to add it - like the I18N plugin "if you want to have external links, add a custom field link and ...". Then check it in your plugin:
Code:
if (function_exists('return_custom_field')) { // I18N Custom Fields installed?
$field = return_custom_field('my_field','default');
...
}