{"action":"created","issue":{"url":"https://api.github.com/repos/ThemeFuse/Unyson/issues/366","labels_url":"https://api.github.com/repos/ThemeFuse/Unyson/issues/366/labels{/name}","comments_url":"https://api.github.com/repos/ThemeFuse/Unyson/issues/366/comments","events_url":"https://api.github.com/repos/ThemeFuse/Unyson/issues/366/events","html_url":"https://github.com/ThemeFuse/Unyson/issues/366","id":62109713,"number":366,"title":"[question] How to convert Unyson options json to option names in JS?","user":{"login":"danyj","id":2340172,"avatar_url":"https://avatars.githubusercontent.com/u/2340172?v=3","gravatar_id":"","url":"https://api.github.com/users/danyj","html_url":"https://github.com/danyj","followers_url":"https://api.github.com/users/danyj/followers","following_url":"https://api.github.com/users/danyj/following{/other_user}","gists_url":"https://api.github.com/users/danyj/gists{/gist_id}","starred_url":"https://api.github.com/users/danyj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danyj/subscriptions","organizations_url":"https://api.github.com/users/danyj/orgs","repos_url":"https://api.github.com/users/danyj/repos","events_url":"https://api.github.com/users/danyj/events{/privacy}","received_events_url":"https://api.github.com/users/danyj/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-03-16T15:09:08Z","updated_at":"2015-03-16T19:02:29Z","closed_at":null,"body":"I was wondering if Unyson has a way to convert  the \r\n\r\n    fw_get_db_settings_option()\r\n\r\nto an array of option names in JS? like \r\n\r\n    name=\"fw_options[option][gadget][custom]\r\n\r\nor ad-least the\r\n\r\n    [option][gadget][custom]\r\n\r\nI started the convert but the json data from ajax request are deep so extracting the exact name is bit of trouble. First levels are oki'sh but further than that is troublesome. \r\n\r\n\t\t\t$.ajax({\r\n\t\t\t  type : 'get',\r\n\t\t\t  dataType : 'json',\r\n\t\t\t  url: ajaxurl,\r\n\t\t\t  data: {\r\n\t\t\t\t'action': 'thz_get_default_options',  \r\n\t\t\t  }\r\n\t\t\t  \r\n\t\t\t  }).done(function(data){\r\n\t\t\t\t  \r\n\t\t\t\t  console.log(data.options);  \r\n\t\t\t\t  for(var x in data.options) {\r\n\t\t\t\t\t  for(var y in data.options[x]) {\r\n\t\t\t\t\t\tconsole.log( \"name of \"+x+\" is: \"+data.options[x][y] );\r\n\t\t\t\t\t  }\r\n\t\t\t\t  }\r\n\r\n\t\t\t\t  \r\n\t\t\t  }).fail(function(jqXHR, textStatus, errorThrown){ \r\n\t\t\t  \t\tconsole.error(jqXHR, textStatus, errorThrown);\r\n\t\t\t  });\r\n\r\n\r\nphp\r\n\r\n\r\nfunction thz_get_default_options() {\r\n\t\r\n\t$options = fw_get_db_settings_option();\r\n\r\n\r\n\t$return = array(\r\n\t\t'options'\t=> $options,\r\n\t);\t\r\n\twp_send_json($return);\r\n}\r\n\r\nadd_action(\"wp_ajax_thz_get_default_options\", \"thz_get_default_options\");\r\n"},"comment":{"url":"https://api.github.com/repos/ThemeFuse/Unyson/issues/comments/81873981","html_url":"https://github.com/ThemeFuse/Unyson/issues/366#issuecomment-81873981","issue_url":"https://api.github.com/repos/ThemeFuse/Unyson/issues/366","id":81873981,"user":{"login":"moldcraft","id":1475489,"avatar_url":"https://avatars.githubusercontent.com/u/1475489?v=3","gravatar_id":"","url":"https://api.github.com/users/moldcraft","html_url":"https://github.com/moldcraft","followers_url":"https://api.github.com/users/moldcraft/followers","following_url":"https://api.github.com/users/moldcraft/following{/other_user}","gists_url":"https://api.github.com/users/moldcraft/gists{/gist_id}","starred_url":"https://api.github.com/users/moldcraft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moldcraft/subscriptions","organizations_url":"https://api.github.com/users/moldcraft/orgs","repos_url":"https://api.github.com/users/moldcraft/repos","events_url":"https://api.github.com/users/moldcraft/events{/privacy}","received_events_url":"https://api.github.com/users/moldcraft/received_events","type":"User","site_admin":false},"created_at":"2015-03-16T19:02:29Z","updated_at":"2015-03-16T19:02:29Z","body":"For e.g. now you expect that (and can confirm that)\r\n\r\n```\r\nfw_options[layout_type][boxed][body_background_type][color][bg_type_color]\r\n```\r\n\r\nwas generate from the database value and exists in the html, so your replace script works.\r\n\r\nBut after some time, for example we will change/improve the color-picker option type, and in html will be\r\n\r\n```\r\nfw_options[layout_type][boxed][body_background_type][color][bg_type_color][type]\r\nfw_options[layout_type][boxed][body_background_type][color][bg_type_color][hex]\r\nfw_options[layout_type][boxed][body_background_type][color][bg_type_color][rgba]\r\n```\r\n\r\n`type` will be a switch that will show/hide hex/rgba color picker. The database value will remain the same (of course, to not have fatal errors in all themes that uses it) but only the html/js will be changes. (this is just an example, we don't have any such plans for color-picker now)\r\n\r\nMy idea is that we do not guarantee that options html will remain the same over time (db values will do), and the input names that you generate manually from db values, now exists and works, but in the future they may not exist and your replace script will not work.\r\n\r\nUnfortunately I don't know a solution for this issue, just want you to understand my warning."}}