Plugins won’t recognize my plugin’s hidden custom fields

In a plugin i developed i created metaboxes in the new/update post page in the admin area that save data into custom fields. In order to prevent confusion or any kind of issues i created those custom fields hidden by adding “_”(underscore) to the beginning of it. Now i realize that other plugins will not recognize those custom fields and not just WordPress so i am looking for a way to fix that as i want my plugin to be able to work together with other plugins.

Obviously just removing the “_” from the name would be the fast and easy way to go. However, users that will do an update to the plugin will have issues since all their data is already saved in the old custom fields.

Read More

One way i was thinking of is adding another set of non hidden custom fields that will hold the same data as the hidden custom fields. so for example if now i have “_address” i will add another fields “address” and whenever the post being saved the data will be saved in both custom fields. This way, users that already have data in the database won’t have any problems using it. However, for the same users ( who updating) the data will not be exist in the new custom fields until the post will be saved again. Means that plugins will recognize the new fields but nothing will be there.

So my first question is , does anyone know on of a better way i can archive that?

and if not , how about a function i can add to the plugin that once a user do an update it will automatically run “save” through all the posts in his database so then i guess the data will be saved in the new custom fields ?
Or maybe a function that will duplicate all the hidden custom fields in the user’s database begins with underscore to custom fields with the same name just without underscore?

[Update – pulled from a Comment]

Well, a quick look into the “post widget” code i found this line
HAVING meta_key NOT LIKE '_%'” which hide hidden custom fields. i
guess plugin developers hide it by default.

Related posts

Leave a Reply

1 comment

  1. Prefixing custom fields with an underscore only results in the keys being hidden from the default custom fields UI:

    enter image description here
    There is nothing preventing plugins or theme code from otherwise querying these keys and their values.