{"id":5352137,"date":"2014-10-02T20:16:44","date_gmt":"2014-10-02T20:16:44","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/import-xml-on-theme-activation\/"},"modified":"2016-08-22T03:05:05","modified_gmt":"2016-08-22T03:05:05","slug":"import-xml-on-theme-activation","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/import-xml-on-theme-activation\/","title":{"rendered":"Import XML on theme activation."},"content":{"rendered":"<p>Hi guys. I have the function <strong>seen bellow<\/strong>, which I call on theme activation, using the <strong>after_switch_theme<\/strong> action:<\/p>\n<pre><code>function herowp_importer_acf(){\n\tglobal $wpdb;\n\n\t\t\t\tif ( !defined(&#039;WP_LOAD_IMPORTERS&#039;) ) define(&#039;WP_LOAD_IMPORTERS&#039;, true); \/\/ we are loading importers\n\n\t\t\t\tif ( ! class_exists( &#039;WP_Importer&#039; ) ) { \/\/ if main importer class doesn&#039;t exist\n\t\t\t\t\t$wp_importer = ABSPATH . &#039;wp-admin\/includes\/class-wp-importer.php&#039;;\n\t\t\t\t\tinclude $wp_importer;\n\t\t\t\t}\n\n\t\t\t\tif ( ! class_exists(&#039;WP_Import&#039;) ) { \/\/ if WP importer doesn&#039;t exist\n\t\t\t\t\t$wp_import = get_template_directory() . &#039;\/inc\/plugins\/importer\/wordpress-importer.php&#039;;\n\t\t\t\t\tinclude $wp_import;\n\t\t\t\t}\n\n\t\t\t\tif ( class_exists( &#039;WP_Importer&#039; ) &amp;&amp; class_exists( &#039;WP_Import&#039; ) ) { \/\/ check for main import class and wp import class\n\n\t\t\t\t\t\t$importer = new WP_Import();\n\n\t\t\t\t\t\t$theme_xml = get_template_directory() . &#039;\/inc\/dummy-data\/xml\/acf.xml.gz&#039;;\n\t\t\t\t\t\t$importer-&gt;fetch_attachments = false;\n\t\t\t\t\t\tob_start();\n\t\t\t\t\t\t$importer-&gt;import($theme_xml);\n\t\t\t\t\t\tob_end_clean();\n\t\t\t\t}\n\n}\nadd_action(&quot;after_switch_theme&quot;, &quot;herowp_importer_theme_options&quot;);<\/code><\/pre>\n<p>but nothing imports. I double checked the xml file, and it&#8217;s all good. Any ideas?<\/p>\n<p>Regards.<\/p>\n","protected":false},"template":"","class_list":["post-5352137","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5352137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5352137\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=5352137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}