Plugin Directory

Changeset 1511372


Ignore:
Timestamp:
10/10/2016 12:24:22 AM (9 years ago)
Author:
judgej
Message:

Changes for 0.6.1

Location:
csv-importer-improved/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • csv-importer-improved/trunk/csv_importer.php

    r1509021 r1511372  
    33Plugin Name: CSV Importer Improved
    44Description: Import data as posts from a CSV file.
    5 Version: 0.6.0
     5Version: 0.6.1
    66Author: Jason judge, Denis Kobozev
    77*/
     
    290290
    291291        $data = array_merge($this->defaults, $data);
    292         $type = $data['csv_post_type'] ? $data['csv_post_type'] : 'post';
     292        $type = $data['csv_post_type'] ?: 'post';
    293293
    294294        // Is this a valid post type?
    295295
    296         $valid_type = (
    297             function_exists('post_type_exists')
    298             && post_type_exists($type)
    299         ) || in_array($type, array('post', 'page'));
    300 
    301         if (!$valid_type) {
     296        $valid_type = (function_exists('post_type_exists') && post_type_exists($type))
     297            || in_array($type, array('post', 'page'));
     298
     299        if (! $valid_type) {
    302300            $this->log['error']["type-{$type}"] = sprintf(
    303301                'Unknown post type "%s".', $type
     
    351349        }
    352350
    353         if (!isset($existing_id) || isset($data['csv_post_date'])) {
     351        if (! isset($existing_id) || isset($data['csv_post_date'])) {
    354352            $new_post['post_date'] = $this->parse_date($data['csv_post_date']);
    355353        }
    356354
    357         if (!isset($existing_id) || isset($data['csv_post_excerpt'])) {
     355        if (! isset($existing_id) || isset($data['csv_post_excerpt'])) {
    358356            $new_post['post_excerpt'] = convert_chars($data['csv_post_excerpt']);
    359357        }
     
    385383        }
    386384
    387         if (!empty($existing_id)) {
     385        // Collect together just the non-null post fields, those that have a value set,
     386        // even if an enpty string.
     387
     388        $set_post_fields = array();
     389        foreach($new_post as $name => $value) {
     390            if ($value !== null) {
     391                $set_post_fields[$name] = $value;
     392            }
     393        }
     394
     395        if (! empty($existing_id)) {
    388396            // Check that the post already exists, and is of the correct type.
    389397            $existing_post_type = get_post_type($existing_id);
    390398
    391             if (!$existing_post_type) {
     399            if (! $existing_post_type) {
    392400                $this->log['error'][] = sprintf(
    393401                    __('Post %d to update does not exist.', 'csv-importer-improved'),
     
    410418
    411419            // Update!
    412             $id = wp_update_post($new_post);
     420            $id = wp_update_post($set_post_fields);
    413421        } else {
    414422            // Create!
    415             $id = wp_insert_post($new_post);
     423            $id = wp_insert_post($set_post_fields);
    416424        }
    417425
  • csv-importer-improved/trunk/readme.txt

    r1509021 r1511372  
    44Requires at least: 3.0.0
    55Tested up to: 4.6.1
    6 Stable tag: 0.6.0
     6Stable tag: 0.6.1
    77
    88Import posts from CSV files into WordPress.
Note: See TracChangeset for help on using the changeset viewer.