Advertisement
sparkweb

CSV Importer Modified 3.7

Mar 22nd, 2013
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.50 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: CSV Importer
  4. Description: Import data as posts from a CSV file. <em>You can reach the author at <a href="mailto:d.v.kobozev@gmail.com">d.v.kobozev@gmail.com</a></em>.
  5. Version: 0.3.7
  6. Author: Denis Kobozev
  7. */
  8.  
  9. /**
  10.  * LICENSE: The MIT License {{{
  11.  *
  12.  * Copyright (c) <2009> <Denis Kobozev>
  13.  *
  14.  * Permission is hereby granted, free of charge, to any person obtaining a copy
  15.  * of this software and associated documentation files (the "Software"), to deal
  16.  * in the Software without restriction, including without limitation the rights
  17.  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  18.  * copies of the Software, and to permit persons to whom the Software is
  19.  * furnished to do so, subject to the following conditions:
  20.  *
  21.  * The above copyright notice and this permission notice shall be included in
  22.  * all copies or substantial portions of the Software.
  23.  *
  24.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27.  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  29.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  30.  * THE SOFTWARE.
  31.  *
  32.  * @author    Denis Kobozev <d.v.kobozev@gmail.com>
  33.  * @copyright 2009 Denis Kobozev
  34.  * @license   The MIT License
  35.  * }}}
  36.  */
  37.  
  38. class CSVImporterPlugin {
  39.     var $defaults = array(
  40.         'csv_post_title'      => null,
  41.         'csv_post_post'       => null,
  42.         'csv_post_type'       => null,
  43.         'csv_post_excerpt'    => null,
  44.         'csv_post_date'       => null,
  45.         'csv_post_tags'       => null,
  46.         'csv_post_categories' => null,
  47.         'csv_post_author'     => null,
  48.         'csv_post_slug'       => null,
  49.         'csv_post_parent'     => 0,
  50.     );
  51.  
  52.     var $log = array();
  53.  
  54.     /**
  55.      * Determine value of option $name from database, $default value or $params,
  56.      * save it to the db if needed and return it.
  57.      *
  58.      * @param string $name
  59.      * @param mixed  $default
  60.      * @param array  $params
  61.      * @return string
  62.      */
  63.     function process_option($name, $default, $params) {
  64.         if (array_key_exists($name, $params)) {
  65.             $value = stripslashes($params[$name]);
  66.         } elseif (array_key_exists('_'.$name, $params)) {
  67.             // unchecked checkbox value
  68.             $value = stripslashes($params['_'.$name]);
  69.         } else {
  70.             $value = null;
  71.         }
  72.         $stored_value = get_option($name);
  73.         if ($value == null) {
  74.             if ($stored_value === false) {
  75.                 if (is_callable($default) &&
  76.                     method_exists($default[0], $default[1])) {
  77.                     $value = call_user_func($default);
  78.                 } else {
  79.                     $value = $default;
  80.                 }
  81.                 add_option($name, $value);
  82.             } else {
  83.                 $value = $stored_value;
  84.             }
  85.         } else {
  86.             if ($stored_value === false) {
  87.                 add_option($name, $value);
  88.             } elseif ($stored_value != $value) {
  89.                 update_option($name, $value);
  90.             }
  91.         }
  92.         return $value;
  93.     }
  94.  
  95.     /**
  96.      * Plugin's interface
  97.      *
  98.      * @return void
  99.      */
  100.     function form() {
  101.         $opt_draft = $this->process_option('csv_importer_import_as_draft',
  102.             'publish', $_POST);
  103.         $opt_cat = $this->process_option('csv_importer_cat', 0, $_POST);
  104.  
  105.         if ('POST' == $_SERVER['REQUEST_METHOD']) {
  106.             $this->post(compact('opt_draft', 'opt_cat'));
  107.         }
  108.  
  109.         // form HTML {{{
  110. ?>
  111.  
  112. <div class="wrap">
  113.     <h2>Import CSV</h2>
  114.     <form class="add:the-list: validate" method="post" enctype="multipart/form-data">
  115.         <!-- Import as draft -->
  116.         <p>
  117.         <input name="_csv_importer_import_as_draft" type="hidden" value="publish" />
  118.         <label><input name="csv_importer_import_as_draft" type="checkbox" <?php if ('draft' == $opt_draft) { echo 'checked="checked"'; } ?> value="draft" /> Import posts as drafts</label>
  119.         </p>
  120.  
  121.         <!-- Parent category -->
  122.         <p>Organize into category <?php wp_dropdown_categories(array('show_option_all' => 'Select one ...', 'hide_empty' => 0, 'hierarchical' => 1, 'show_count' => 0, 'name' => 'csv_importer_cat', 'orderby' => 'name', 'selected' => $opt_cat));?><br/>
  123.             <small>This will create new categories inside the category parent you choose.</small></p>
  124.  
  125.         <!-- File input -->
  126.         <p><label for="csv_import">Upload file:</label><br/>
  127.             <input name="csv_import" id="csv_import" type="file" value="" aria-required="true" /></p>
  128.         <p class="submit"><input type="submit" class="button" name="submit" value="Import" /></p>
  129.     </form>
  130. </div><!-- end wrap -->
  131.  
  132. <?php
  133.         // end form HTML }}}
  134.  
  135.     }
  136.  
  137.     function print_messages() {
  138.         if (!empty($this->log)) {
  139.  
  140.         // messages HTML {{{
  141. ?>
  142.  
  143. <div class="wrap">
  144.     <?php if (!empty($this->log['error'])): ?>
  145.  
  146.     <div class="error">
  147.  
  148.         <?php foreach ($this->log['error'] as $error): ?>
  149.             <p><?php echo $error; ?></p>
  150.         <?php endforeach; ?>
  151.  
  152.     </div>
  153.  
  154.     <?php endif; ?>
  155.  
  156.     <?php if (!empty($this->log['notice'])): ?>
  157.  
  158.     <div class="updated fade">
  159.  
  160.         <?php foreach ($this->log['notice'] as $notice): ?>
  161.             <p><?php echo $notice; ?></p>
  162.         <?php endforeach; ?>
  163.  
  164.     </div>
  165.  
  166.     <?php endif; ?>
  167. </div><!-- end wrap -->
  168.  
  169. <?php
  170.         // end messages HTML }}}
  171.  
  172.             $this->log = array();
  173.         }
  174.     }
  175.  
  176.     /**
  177.      * Handle POST submission
  178.      *
  179.      * @param array $options
  180.      * @return void
  181.      */
  182.     function post($options) {
  183.         if (empty($_FILES['csv_import']['tmp_name'])) {
  184.             $this->log['error'][] = 'No file uploaded, aborting.';
  185.             $this->print_messages();
  186.             return;
  187.         }
  188.  
  189.         require_once 'File_CSV_DataSource/DataSource.php';
  190.  
  191.         $time_start = microtime(true);
  192.         $csv = new File_CSV_DataSource;
  193.         $file = $_FILES['csv_import']['tmp_name'];
  194.         $this->stripBOM($file);
  195.  
  196.         if (!$csv->load($file)) {
  197.             $this->log['error'][] = 'Failed to load file, aborting.';
  198.             $this->print_messages();
  199.             return;
  200.         }
  201.  
  202.         // pad shorter rows with empty values
  203.         $csv->symmetrize();
  204.  
  205.         // WordPress sets the correct timezone for date functions somewhere
  206.         // in the bowels of wp_insert_post(). We need strtotime() to return
  207.         // correct time before the call to wp_insert_post().
  208.         $tz = get_option('timezone_string');
  209.         if ($tz && function_exists('date_default_timezone_set')) {
  210.             date_default_timezone_set($tz);
  211.         }
  212.  
  213.         $skipped = 0;
  214.         $imported = 0;
  215.         $comments = 0;
  216.         foreach ($csv->connect() as $csv_data) {
  217.             if ($post_id = $this->create_post($csv_data, $options)) {
  218.                 $imported++;
  219.                 $comments += $this->add_comments($post_id, $csv_data);
  220.                 $this->create_custom_fields($post_id, $csv_data);
  221.         $this->upload_images($post_id, $csv_data);
  222.             } else {
  223.                 $skipped++;
  224.             }
  225.         }
  226.  
  227.         if (file_exists($file)) {
  228.             @unlink($file);
  229.         }
  230.  
  231.         $exec_time = microtime(true) - $time_start;
  232.  
  233.         if ($skipped) {
  234.             $this->log['notice'][] = "<b>Skipped {$skipped} posts (most likely due to empty title, body and excerpt).</b>";
  235.         }
  236.         $this->log['notice'][] = sprintf("<b>Imported {$imported} posts and {$comments} comments in %.2f seconds.</b>", $exec_time);
  237.         $this->print_messages();
  238.     }
  239.  
  240.     function create_post($data, $options) {
  241.         extract($options);
  242.  
  243.         $data = array_merge($this->defaults, $data);
  244.         $type = $data['csv_post_type'] ? $data['csv_post_type'] : 'post';
  245.         $valid_type = (function_exists('post_type_exists') &&
  246.             post_type_exists($type)) || in_array($type, array('post', 'page'));
  247.  
  248.         if (!$valid_type) {
  249.             $this->log['error']["type-{$type}"] = sprintf(
  250.                 'Unknown post type "%s".', $type);
  251.         }
  252.  
  253.         $new_post = array(
  254.             'post_title'   => convert_chars($data['csv_post_title']),
  255.             'post_content' => wpautop(convert_chars($data['csv_post_post'])),
  256.             'post_status'  => $opt_draft,
  257.             'post_type'    => $type,
  258.             'post_date'    => $this->parse_date($data['csv_post_date']),
  259.             'post_excerpt' => convert_chars($data['csv_post_excerpt']),
  260.             'post_name'    => $data['csv_post_slug'],
  261.             'post_author'  => $this->get_auth_id($data['csv_post_author']),
  262.             'tax_input'    => $this->get_taxonomies($data),
  263.             'post_parent'  => $data['csv_post_parent'],
  264.         );
  265.  
  266.         // pages don't have tags or categories
  267.         if ('page' !== $type) {
  268.             $new_post['tags_input'] = $data['csv_post_tags'];
  269.  
  270.             // Setup categories before inserting - this should make insertion
  271.             // faster, but I don't exactly remember why :) Most likely because
  272.             // we don't assign default cat to post when csv_post_categories
  273.             // is not empty.
  274.             $cats = $this->create_or_get_categories($data, $opt_cat);
  275.             $new_post['post_category'] = $cats['post'];
  276.         }
  277.  
  278.         // create!
  279.         $id = wp_insert_post($new_post);
  280.  
  281.         if ('page' !== $type && !$id) {
  282.             // cleanup new categories on failure
  283.             foreach ($cats['cleanup'] as $c) {
  284.                 wp_delete_term($c, 'category');
  285.             }
  286.         }
  287.         return $id;
  288.     }
  289.  
  290.     /**
  291.      * Return an array of category ids for a post.
  292.      *
  293.      * @param string  $data csv_post_categories cell contents
  294.      * @param integer $common_parent_id common parent id for all categories
  295.      * @return array category ids
  296.      */
  297.     function create_or_get_categories($data, $common_parent_id) {
  298.         $ids = array(
  299.             'post' => array(),
  300.             'cleanup' => array(),
  301.         );
  302.         $items = array_map('trim', explode(',', $data['csv_post_categories']));
  303.         foreach ($items as $item) {
  304.             if (is_numeric($item)) {
  305.                 if (get_category($item) !== null) {
  306.                     $ids['post'][] = $item;
  307.                 } else {
  308.                     $this->log['error'][] = "Category ID {$item} does not exist, skipping.";
  309.                 }
  310.             } else {
  311.                 $parent_id = $common_parent_id;
  312.                 // item can be a single category name or a string such as
  313.                 // Parent > Child > Grandchild
  314.                 $categories = array_map('trim', explode('>', $item));
  315.                 if (count($categories) > 1 && is_numeric($categories[0])) {
  316.                     $parent_id = $categories[0];
  317.                     if (get_category($parent_id) !== null) {
  318.                         // valid id, everything's ok
  319.                         $categories = array_slice($categories, 1);
  320.                     } else {
  321.                         $this->log['error'][] = "Category ID {$parent_id} does not exist, skipping.";
  322.                         continue;
  323.                     }
  324.                 }
  325.                 foreach ($categories as $category) {
  326.                     if ($category) {
  327.                         $term = $this->term_exists($category, 'category', $parent_id);
  328.                         if ($term) {
  329.                             $term_id = $term['term_id'];
  330.                         } else {
  331.                             $term_id = wp_insert_category(array(
  332.                                 'cat_name' => $category,
  333.                                 'category_parent' => $parent_id,
  334.                             ));
  335.                             $ids['cleanup'][] = $term_id;
  336.                         }
  337.                         $parent_id = $term_id;
  338.                     }
  339.                 }
  340.                 $ids['post'][] = $term_id;
  341.             }
  342.         }
  343.         return $ids;
  344.     }
  345.  
  346.     /**
  347.      * Parse taxonomy data from the file
  348.      *
  349.      * array(
  350.      *      // hierarchical taxonomy name => ID array
  351.      *      'my taxonomy 1' => array(1, 2, 3, ...),
  352.      *      // non-hierarchical taxonomy name => term names string
  353.      *      'my taxonomy 2' => array('term1', 'term2', ...),
  354.      * )
  355.      *
  356.      * @param array $data
  357.      * @return array
  358.      */
  359.     function get_taxonomies($data) {
  360.         $taxonomies = array();
  361.         foreach ($data as $k => $v) {
  362.             if (preg_match('/^csv_ctax_(.*)$/', $k, $matches)) {
  363.                 $t_name = $matches[1];
  364.                 if ($this->taxonomy_exists($t_name)) {
  365.                     $taxonomies[$t_name] = $this->create_terms($t_name,
  366.                         $data[$k]);
  367.                 } else {
  368.                     $this->log['error'][] = "Unknown taxonomy $t_name";
  369.                 }
  370.             }
  371.         }
  372.         return $taxonomies;
  373.     }
  374.  
  375.     /**
  376.      * Return an array of term IDs for hierarchical taxonomies or the original
  377.      * string from CSV for non-hierarchical taxonomies. The original string
  378.      * should have the same format as csv_post_tags.
  379.      *
  380.      * @param string $taxonomy
  381.      * @param string $field
  382.      * @return mixed
  383.      */
  384.     function create_terms($taxonomy, $field) {
  385.         if (is_taxonomy_hierarchical($taxonomy)) {
  386.             $term_ids = array();
  387.             foreach ($this->_parse_tax($field) as $row) {
  388.                 list($parent, $child) = $row;
  389.                 $parent_ok = true;
  390.                 if ($parent) {
  391.                     $parent_info = $this->term_exists($parent, $taxonomy);
  392.                     if (!$parent_info) {
  393.                         // create parent
  394.                         $parent_info = wp_insert_term($parent, $taxonomy);
  395.                     }
  396.                     if (!is_wp_error($parent_info)) {
  397.                         $parent_id = $parent_info['term_id'];
  398.                     } else {
  399.                         // could not find or create parent
  400.                         $parent_ok = false;
  401.                     }
  402.                 } else {
  403.                     $parent_id = 0;
  404.                 }
  405.  
  406.                 if ($parent_ok) {
  407.                     $child_info = $this->term_exists($child, $taxonomy, $parent_id);
  408.                     if (!$child_info) {
  409.                         // create child
  410.                         $child_info = wp_insert_term($child, $taxonomy,
  411.                             array('parent' => $parent_id));
  412.                     }
  413.                     if (!is_wp_error($child_info)) {
  414.                         $term_ids[] = $child_info['term_id'];
  415.                     }
  416.                 }
  417.             }
  418.             return $term_ids;
  419.         } else {
  420.             return $field;
  421.         }
  422.     }
  423.  
  424.     /**
  425.      * Compatibility wrapper for WordPress term lookup.
  426.      */
  427.     function term_exists($term, $taxonomy = '', $parent = 0) {
  428.         if (function_exists('term_exists')) { // 3.0 or later
  429.             return term_exists($term, $taxonomy, $parent);
  430.         } else {
  431.             return is_term($term, $taxonomy, $parent);
  432.         }
  433.     }
  434.  
  435.     /**
  436.      * Compatibility wrapper for WordPress taxonomy lookup.
  437.      */
  438.     function taxonomy_exists($taxonomy) {
  439.         if (function_exists('taxonomy_exists')) { // 3.0 or later
  440.             return taxonomy_exists($taxonomy);
  441.         } else {
  442.             return is_taxonomy($taxonomy);
  443.         }
  444.     }
  445.  
  446.     /**
  447.      * Hierarchical taxonomy fields are tiny CSV files in their own right.
  448.      *
  449.      * @param string $field
  450.      * @return array
  451.      */
  452.     function _parse_tax($field) {
  453.         $data = array();
  454.         if (function_exists('str_getcsv')) { // PHP 5 >= 5.3.0
  455.             $lines = $this->split_lines($field);
  456.  
  457.             foreach ($lines as $line) {
  458.                 $data[] = str_getcsv($line, ',', '"');
  459.             }
  460.         } else {
  461.             // Use temp files for older PHP versions. Reusing the tmp file for
  462.             // the duration of the script might be faster, but not necessarily
  463.             // significant.
  464.             $handle = tmpfile();
  465.             fwrite($handle, $field);
  466.             fseek($handle, 0);
  467.  
  468.             while (($r = fgetcsv($handle, 999999, ',', '"')) !== false) {
  469.                 $data[] = $r;
  470.             }
  471.             fclose($handle);
  472.         }
  473.         return $data;
  474.     }
  475.  
  476.     /**
  477.      * Try to split lines of text correctly regardless of the platform the text
  478.      * is coming from.
  479.      */
  480.     function split_lines($text) {
  481.         $lines = preg_split("/(\r\n|\n|\r)/", $text);
  482.         return $lines;
  483.     }
  484.  
  485.     function add_comments($post_id, $data) {
  486.         // First get a list of the comments for this post
  487.         $comments = array();
  488.         foreach ($data as $k => $v) {
  489.             // comments start with cvs_comment_
  490.             if (    preg_match('/^csv_comment_([^_]+)_(.*)/', $k, $matches) &&
  491.                     $v != '') {
  492.                 $comments[$matches[1]] = 1;
  493.             }
  494.         }
  495.         // Sort this list which specifies the order they are inserted, in case
  496.         // that matters somewhere
  497.         ksort($comments);
  498.  
  499.         // Now go through each comment and insert it. More fields are possible
  500.         // in principle (see docu of wp_insert_comment), but I didn't have data
  501.         // for them so I didn't test them, so I didn't include them.
  502.         $count = 0;
  503.         foreach ($comments as $cid => $v) {
  504.             $new_comment = array(
  505.                 'comment_post_ID' => $post_id,
  506.                 'comment_approved' => 1,
  507.             );
  508.  
  509.             if (isset($data["csv_comment_{$cid}_author"])) {
  510.                 $new_comment['comment_author'] = convert_chars(
  511.                     $data["csv_comment_{$cid}_author"]);
  512.             }
  513.             if (isset($data["csv_comment_{$cid}_author_email"])) {
  514.                 $new_comment['comment_author_email'] = convert_chars(
  515.                     $data["csv_comment_{$cid}_author_email"]);
  516.             }
  517.             if (isset($data["csv_comment_{$cid}_url"])) {
  518.                 $new_comment['comment_author_url'] = convert_chars(
  519.                     $data["csv_comment_{$cid}_url"]);
  520.             }
  521.             if (isset($data["csv_comment_{$cid}_content"])) {
  522.                 $new_comment['comment_content'] = convert_chars(
  523.                     $data["csv_comment_{$cid}_content"]);
  524.             }
  525.             if (isset($data["csv_comment_{$cid}_date"])) {
  526.                 $new_comment['comment_date'] = $this->parse_date(
  527.                     $data["csv_comment_{$cid}_date"]);
  528.             }
  529.  
  530.             $id = wp_insert_comment($new_comment);
  531.             if ($id) {
  532.                 $count++;
  533.             } else {
  534.                 $this->log['error'][] = "Could not add comment $cid";
  535.             }
  536.         }
  537.         return $count;
  538.     }
  539.  
  540.     function create_custom_fields($post_id, $data) {
  541.         foreach ($data as $k => $v) {
  542.             // anything that doesn't start with csv_ is a custom field
  543.             if (!preg_match('/^csv_/', $k) && $v != '') {
  544.                 add_post_meta($post_id, $k, $v);
  545.             }
  546.         }
  547.     }
  548.  
  549.     function upload_images($post_id, $data) {
  550.         foreach ($data as $k => $v) {
  551.         $image = "";
  552.         if (strpos($k, "csv_image") !== false && $v != '') $image = $v;
  553.         if ($image) {
  554.             $upload_dir = wp_upload_dir();
  555.             $targetFile = $upload_dir['path'] . '/' . sanitize_file_name(basename($image));
  556.  
  557.             $ch = curl_init ($image);
  558.             curl_setopt($ch, CURLOPT_HEADER, 0);
  559.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 10);
  560.             curl_setopt($ch, CURLOPT_BINARYTRANSFER,10);
  561.             $rawdata=curl_exec($ch);
  562.             curl_close($ch);
  563.             $fp = fopen($targetFile,'w');
  564.             fwrite($fp, $rawdata);
  565.             fclose($fp);
  566.  
  567.             //Setup New Image
  568.             $wp_filetype = wp_check_filetype(basename($targetFile), null);
  569.             $attachment = array(
  570.                 'post_mime_type' => $wp_filetype['type'],
  571.                 'post_title' => get_the_title($post_id),
  572.                 'guid' => $upload_dir['url'] . "/" . basename($targetFile),
  573.                 'menu_order' => 1,
  574.                 'post_content' => '',
  575.                 'post_status' => 'inherit'
  576.             );
  577.             require_once(ABSPATH . "wp-admin" . '/includes/image.php');
  578.             $attach_id = wp_insert_attachment($attachment, $targetFile, $post_id);
  579.             $attach_data = wp_generate_attachment_metadata($attach_id, $targetFile);
  580.             wp_update_attachment_metadata($attach_id, $attach_data);
  581.  
  582.             update_post_meta($post_id,"_thumbnail_id",$attach_id);
  583.         }
  584.     }
  585.     }
  586.  
  587.  
  588.     function get_auth_id($author) {
  589.         if (is_numeric($author)) {
  590.             return $author;
  591.         }
  592.         $author_data = get_userdatabylogin($author);
  593.         return ($author_data) ? $author_data->ID : 0;
  594.     }
  595.  
  596.     /**
  597.      * Convert date in CSV file to 1999-12-31 23:52:00 format
  598.      *
  599.      * @param string $data
  600.      * @return string
  601.      */
  602.     function parse_date($data) {
  603.         $timestamp = strtotime($data);
  604.         if (false === $timestamp) {
  605.             return '';
  606.         } else {
  607.             return date('Y-m-d H:i:s', $timestamp);
  608.         }
  609.     }
  610.  
  611.     /**
  612.      * Delete BOM from UTF-8 file.
  613.      *
  614.      * @param string $fname
  615.      * @return void
  616.      */
  617.     function stripBOM($fname) {
  618.         $res = fopen($fname, 'rb');
  619.         if (false !== $res) {
  620.             $bytes = fread($res, 3);
  621.             if ($bytes == pack('CCC', 0xef, 0xbb, 0xbf)) {
  622.                 $this->log['notice'][] = 'Getting rid of byte order mark...';
  623.                 fclose($res);
  624.  
  625.                 $contents = file_get_contents($fname);
  626.                 if (false === $contents) {
  627.                     trigger_error('Failed to get file contents.', E_USER_WARNING);
  628.                 }
  629.                 $contents = substr($contents, 3);
  630.                 $success = file_put_contents($fname, $contents);
  631.                 if (false === $success) {
  632.                     trigger_error('Failed to put file contents.', E_USER_WARNING);
  633.                 }
  634.             } else {
  635.                 fclose($res);
  636.             }
  637.         } else {
  638.             $this->log['error'][] = 'Failed to open file, aborting.';
  639.         }
  640.     }
  641. }
  642.  
  643.  
  644. function csv_admin_menu() {
  645.     require_once ABSPATH . '/wp-admin/admin.php';
  646.     $plugin = new CSVImporterPlugin;
  647.     add_management_page('edit.php', 'CSV Importer', 'manage_options', __FILE__,
  648.         array($plugin, 'form'));
  649. }
  650.  
  651. add_action('admin_menu', 'csv_admin_menu');
  652.  
  653. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement