Widget Compatibility/Problem with saving data
-
Hi,
first off thank you for this great plugin! I can translate Posts fine and the language switcher works, all great!
I just have a problem with Widgets. Now there seems to be a Problem when saving Data. You can reproduce it easily when installing WP-Multilang and Social Icons By WPZOOM. Now add the widget to an area and try adding/deleting social links. On save it will always revert back to it’s initial state.
Now I’d be fine disabling the translation functionality for all widgets but I can’t figure out how to do that either. I added the “wpm-config.json” in my child theme and added the following:
{ "admin_pages": [ "upload", "nav-menus", "options-general", "settings-network", "site-settings-network" ], "widgets": {} }I also tried setting “widgets” to none and placing the file into my parent themes directory.
Can you help?
-
Hi @doubleyoustew
In “admin_pages” section You need to add IDs of current admin screen. All this screen IDs, what You added already exist in configuration.In “widget” section, You need to add widget IDs and its fields.
As example from core config:"widgets": { "media_image": { "caption": {}, "alt": {}, "image_title": {} }, "custom_html": { "content": {} } }Hey @valexar,
thanks for the quick reply! I’m having problems setting this up unfortunately. My widget is laid out like this (this is a dump of $new_instance when updating the widget data):
array(2) { ["title"]=> string(4) "test" ["locations"]=> array(1) { [0]=> array(3) { ["latlong"]=> string(7) "123/123" ["name"]=> string(8) "testname" ["url"]=> string(5) "/test" } } }And this is what I’ve added to the wpm-config.json:
{ "widgets": { "hestia-child-map-widget": { "title": {}, "locations": [ "latlong", "name", "url" ] } } }I’ve also tried it like this:
{ "widgets": { "hestia-child-map-widget": { "title": {}, "locations": { "latlong": {}, "name": {}, "url": {} } } } }But it’s not working. The exact problem I’m having is that since “locations” is an array, I need to be able to unset certain keys to be removed. But if I enable your plugin it doesn’t save the retuned instance properly. I can change values but I can’t delete basically.
So I unset all the array keys where name and latlong is empty but the data it will be saving looks more like this:
array(2) { ["title"]=> string(12) "[:de]Test[:]" ["locations"]=> array(3) { [0]=> array(3) { ["latlong"]=> string(7) "123/123" ["name"]=> string(8) "TestName" ["url"]=> string(6) "/test2" } [1]=> array(3) { ["latlong"]=> string(0) "" ["name"]=> string(0) "" ["url"]=> string(0) "" } [2]=> array(3) { ["latlong"]=> string(0) "" ["name"]=> string(0) "" ["url"]=> string(0) "" } } }Sorry for the wall of text, I’m very lost here..
-
This reply was modified 8 years, 3 months ago by
doubleyoustew.
@doubleyoustew
The title of widget is translating by default. You need translate another fields.
Use “wpm_each” tag for set in translate each element in a array.{ "widgets": { "hestia-child-map-widget": { "locations": { "wpm_each": { "latlong": {}, "name": {}, "url": {} } } } } }@valexar Thanks, I can translate the fields now. However I still have the same bug. If I unset array keys the deleted items are not being deleted.
So what I’m guessing is happening is that on widget update() I’m getting the $instance of only one language. If I unset the empty fields they are still there in the other language and thus are not being deleted. So if I get the “en” instance and delete the keys, they are still there in the “de” instance and are being merged and are still there in the end. My guess is that behind the scenes the Widgets for each language are really the same dataset but with the [:en] tags etc.
I’m attaching the code of my widget so you can see what I’m trying to do. I don’t know if this is a bug with your plugin or my implementation is just sucks 😉
The same thing happens with the “Social Icons by WPZOOM” widget as well. Widgets not being translatable by default is fine, but IMHO your plugin shouldn’t break the functionality, especially if the proper json structure of the widget is added.
Cheers! 🙂
Edit: Just to confirm, I added this JSON for the Social Icons widget and you can’t even save the Icons (try altering the default domains for the facebook link for example). So either I’m still doing it wrong or there is a bug with your plugin :/
Edit2: Btw I’d still be fine with just disabling the translations for the widget area. I don’t really need my widgets to be translatable. I just need it to save data correctly 😀
-
This reply was modified 8 years, 3 months ago by
doubleyoustew.
-
This reply was modified 8 years, 3 months ago by
doubleyoustew.
Hey @valexar,
I still have that same problem. I tried to disable the translation but it doesn’t work either:
{ "widgets": { "hestia-child-map-widget": { "locations": { "wpm_each": { "latlong": null, "name": null, "url": null } } } } }Ok.
The latest way is set config by filter.
Try to use these filters:
‘wpm_widgets_config’
‘wpm_widget_{$widget_id}_config’
This must definitely help. -
This reply was modified 8 years, 3 months ago by
The topic ‘Widget Compatibility/Problem with saving data’ is closed to new replies.