Changeset 1511372
- Timestamp:
- 10/10/2016 12:24:22 AM (9 years ago)
- Location:
- csv-importer-improved/trunk
- Files:
-
- 2 edited
-
csv_importer.php (modified) (5 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
csv-importer-improved/trunk/csv_importer.php
r1509021 r1511372 3 3 Plugin Name: CSV Importer Improved 4 4 Description: Import data as posts from a CSV file. 5 Version: 0.6. 05 Version: 0.6.1 6 6 Author: Jason judge, Denis Kobozev 7 7 */ … … 290 290 291 291 $data = array_merge($this->defaults, $data); 292 $type = $data['csv_post_type'] ? $data['csv_post_type']: 'post';292 $type = $data['csv_post_type'] ?: 'post'; 293 293 294 294 // Is this a valid post type? 295 295 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) { 302 300 $this->log['error']["type-{$type}"] = sprintf( 303 301 'Unknown post type "%s".', $type … … 351 349 } 352 350 353 if (! isset($existing_id) || isset($data['csv_post_date'])) {351 if (! isset($existing_id) || isset($data['csv_post_date'])) { 354 352 $new_post['post_date'] = $this->parse_date($data['csv_post_date']); 355 353 } 356 354 357 if (! isset($existing_id) || isset($data['csv_post_excerpt'])) {355 if (! isset($existing_id) || isset($data['csv_post_excerpt'])) { 358 356 $new_post['post_excerpt'] = convert_chars($data['csv_post_excerpt']); 359 357 } … … 385 383 } 386 384 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)) { 388 396 // Check that the post already exists, and is of the correct type. 389 397 $existing_post_type = get_post_type($existing_id); 390 398 391 if (! $existing_post_type) {399 if (! $existing_post_type) { 392 400 $this->log['error'][] = sprintf( 393 401 __('Post %d to update does not exist.', 'csv-importer-improved'), … … 410 418 411 419 // Update! 412 $id = wp_update_post($ new_post);420 $id = wp_update_post($set_post_fields); 413 421 } else { 414 422 // Create! 415 $id = wp_insert_post($ new_post);423 $id = wp_insert_post($set_post_fields); 416 424 } 417 425 -
csv-importer-improved/trunk/readme.txt
r1509021 r1511372 4 4 Requires at least: 3.0.0 5 5 Tested up to: 4.6.1 6 Stable tag: 0.6. 06 Stable tag: 0.6.1 7 7 8 8 Import posts from CSV files into WordPress.
Note: See TracChangeset
for help on using the changeset viewer.