{"id":1024,"date":"2022-01-17T22:24:28","date_gmt":"2022-01-17T22:24:28","guid":{"rendered":"https:\/\/oc-soft.net\/?p=1024"},"modified":"2022-04-26T10:12:07","modified_gmt":"2022-04-26T10:12:07","slug":"create-customizer-control","status":"publish","type":"post","link":"https:\/\/oc-soft.net\/en\/create-customizer-control\/","title":{"rendered":"wp.api.Element may be called twice."},"content":{"rendered":"\n<p>api.Element initialize might be called 2 times in api.Control initialize method. <\/p>\n\n\n\n<p>On php side generate setting json in administrator page at <a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/c20c8a99bdd09ad549f1b9705f4af3f721d0ea99\/wp-includes\/class-wp-customize-manager.php#L4971\">this location<\/a>. Your extended a class from <a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/c20c8a99bdd09ad549f1b9705f4af3f721d0ea99\/wp-includes\/class-wp-customize-control.php#L15\">WP_Customizer_Control<\/a> is called <a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/c20c8a99bdd09ad549f1b9705f4af3f721d0ea99\/wp-includes\/class-wp-customize-control.php#L308\">to_json<\/a> method on it. In to_json method, WP_Customizer_Control generate default control template string <a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/c20c8a99bdd09ad549f1b9705f4af3f721d0ea99\/wp-includes\/class-wp-customize-control.php#L318\">here<\/a>. This template string contains input html tag with your specified tag. The input html tag in template string cause wp.api.Element calling first time. If you override content_template method in your class from WP_Customizer_Control, wp.api.Control will detect the template from content_template and create html elements and replace first time wp.api.Element.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/c20c8a99bdd09ad549f1b9705f4af3f721d0ea99\/wp-admin\/js\/customize-controls.js#L3696\">This line<\/a> is wp.api.Element calling from wp.api.Control. it is located in <a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/c20c8a99bdd09ad549f1b9705f4af3f721d0ea99\/wp-admin\/js\/customize-controls.js#L3664\">wp.api.Control.linkElements<\/a>.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/c20c8a99bdd09ad549f1b9705f4af3f721d0ea99\/wp-admin\/js\/customize-controls.js#L3638\">This line<\/a> is first time call wp.api.Control.linkElements.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/c20c8a99bdd09ad549f1b9705f4af3f721d0ea99\/wp-admin\/js\/customize-controls.js#L3650\">This line<\/a> is second time call wp.api.Control.linkElements.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>api.Element initialize might be called 2 times in api.Control initialize method. On php side generate setting json in administrator page at this location. Your extended a class from WP_Customizer_Control is called to_json method on it. In to_json method, WP_Customizer_Control generate default control template string here. This template string contains input html tag with your specified [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1028,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/oc-soft.net\/?p=1024","footnotes":""},"categories":[1],"tags":[],"class_list":["post-1024","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","en-US"],"_links":{"self":[{"href":"https:\/\/oc-soft.net\/wp-json\/wp\/v2\/posts\/1024","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oc-soft.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oc-soft.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oc-soft.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oc-soft.net\/wp-json\/wp\/v2\/comments?post=1024"}],"version-history":[{"count":7,"href":"https:\/\/oc-soft.net\/wp-json\/wp\/v2\/posts\/1024\/revisions"}],"predecessor-version":[{"id":1038,"href":"https:\/\/oc-soft.net\/wp-json\/wp\/v2\/posts\/1024\/revisions\/1038"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oc-soft.net\/wp-json\/wp\/v2\/media\/1028"}],"wp:attachment":[{"href":"https:\/\/oc-soft.net\/wp-json\/wp\/v2\/media?parent=1024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oc-soft.net\/wp-json\/wp\/v2\/categories?post=1024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oc-soft.net\/wp-json\/wp\/v2\/tags?post=1024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}