Home › Forums › General Issues › Changing the way ACF saves widget fields
Please correct me if I’m mistaken, but normally widget fields data is stored as a serialized array in a single DB entry.
However ACF saves each widget field as an individual DB entry, causing some compatibility issues.
For example we’re unable to use Widget Export / Import plugin, because it can’t fetch the ACF widget fields.
Is there a chance to resolve the issue?
Anyway, thanks a lot for ACF!
The data you’re talking about being saved in a serialized array is data saved by WP. ACf stores data for widgets consistent with the way is saves data for all fields it manages.
I was curious so I looked into it a bit more. Rather than just say I don’t thinks is possible I thought I would explain why.
Saving this information along with the standard widget information would require hooking into where WP saves the data for a widget. Unfortunately WP does not provide any hooks in the core widgets that will let you do this, and since WP doesm’t do it I doubt that widget authors do it either. Without these hooks it’s not possible to make this happen.
If there was a way to hook into the widget save then you’d also need to hook into the load_value hook of ACF to get the current values from the widget. This part would be completely possible if you could do the first part.
To export and import you’d need a plugin that’s aware of ACF. I don’t think there is one.
Thanks John for such a detailed response.
widget_update_callback hook, check here.
I think it can be the hook you need. See an article here regarding cache clearing upon widget save.
Basicaly you could get defaul widget settings, append the ones from ACF and save it back to the default serialized array.
Even so, I’m not sure this is something that the developer is going to want to add to ACF, at least not in a hurry. If this is something you need right away I’d suggest looking into making it happen.
For an example of something similar take a look at this topic that has several example of updating term_meta and retrieving the values. This is something that others worked on until the developer figures out how to implement term meta in ACF https://support.advancedcustomfields.com/forums/topic/how-to-use-wp-term-meta-on-acf-the-easy-way/.
This actually seems interesting and when I find some time I’ll probably look into it myself, it could be something handy to have for other reasons, but I don’t think I’m going to be able to get to it right away.
Unfortunately, I’m a poor coder to contribute. Would be great if you could look into it.
Thanks a lot, John!
I’ve been looking into this, and it’s not something that’s going to be possible. I was looking at the plugin that you’re using for the export/import, I think you meant this one https://wordpress.org/plugins/widget-importer-exporter/. It seems to be a well maintained plugin and it appears that the author is actively supporting it. My suggestion would be to contact the plugin author. I see that there are hooks in both the import and export functions. I’m not very familiar with the plugin, but it may be possible for you to create a filter that will add the ACF fields to the export and then another filter that will let you import the ACF fields, but you’d need to get more information from the other plugin developer on how those filters work. It that’s not the plugin you’re using let me know what the correct one is.
Thanks for investigating, John. Yes, it’s the plugin I’m using for export.
I’m using this one for import though: https://ru.wordpress.org/plugins/one-click-demo-import/. It’s also well maintained by the developer.
I’m not sure what filters I would exactly need for including ACF fields in the export files and in the import process.
Would highly appreciate any help and directions. Thanks a lot!
I looked at the code of the import/export plugin, not the other one. The one I looked at already includes filters that will let you include extra data in the export and then to do something with it in the import, but there isn’t any documentation I can find on how to use it. With information on how to use it someone could probably create filters that let you transfer ACF fields for widgets. But this would likely mean you need to use the same plugin for both export and import. Is there a reason you’re using separate ones?
I’m exporting widgets to save the fields in a file. Then I’m including this file with a theme along with an xml-file of exported posts, so that users may import all the demo content in one click, not only widgets.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.