<?php

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

class ImportarXml
{

    public function __construct()
    {
        $this->main();
    }

    public function main()
    {


        $data = plugin_dir_path(__FILE__, true) . 'formularios.xml';
        $data = 'C:\Servidor\www\altimus\wp-content\plugins\altimus\inc\import\formularios.xml';

        $file = file_get_contents($data);
        $xml = simplexml_load_string($file);
        $size = count($xml->channel->item);
        $hasData = false;
        $inserted_post_ids = array();


        if ($size > 0) {
            $hasData = true;
        }

        if ($hasData) {
            foreach ($xml->channel->item as $item) {

                var_dump($item->getElementsByTagName('encoded')->item(0)->nodeValue);

                die;

                $author_id = 1;
                $postCreated = array(
                    'post_title' => $item->title . " IMPORTADO",
                    'post_content' => $item->content,
                    'post_excerpt' => $item->excerpt,
                    'post_status' => 'publish',
                    'ping_status' => 'closed',
                    //'post_author' => $author_id,
                    'post_type' => 'wpcf7_contact_form', // Or "page" or some custom post type
                );

                //$result = wp_insert_post( $postCreated );
                die('fim');


                if ($result > 0) {

                    $inserted_post_id = $result;

                    //add all post meta info
                    add_post_meta($inserted_post_id, 'content_type', $post_type);

                    //update the list of inserted post ids
                    $inserted_post_ids[] = $inserted_post_id;
                }

            }

        } // end post insertion

    }


}

add_action('init', 'importacao_conteudo');

function importacao_conteudo()
{
    //$class = new ImportarXml();
}

