Really Simple CSV Importer - Version 0.4

Version Description

  • New feature: Added custom taxonomy support. Thanks chuckhendo!
Download this release

Release Info

Developer hissy
Plugin Icon wp plugin Really Simple CSV Importer
Version 0.4
Comparing to
See all releases

Code changes from version 0.3 to 0.4

readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Really Simple CSV Importer ===
2
  Contributors: hissy, wokamoto
3
- Tags: importer, csv
4
  Requires at least: 3.0
5
  Tested up to: 3.6.1
6
- Stable tag: 0.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -17,7 +17,8 @@ Alternative CSV Importer plugin. Simple and powerful.
17
  * Tag support
18
  * Custom field support
19
  * Adcanved Custom Fields support (beta)
20
- * Custom post type support
 
21
 
22
  Contains CSV file sample in `/wp-content/plugins/really-simple-csv-importer/sample` directory.
23
 
@@ -28,16 +29,20 @@ Contains CSV file sample in `/wp-content/plugins/really-simple-csv-importer/samp
28
  * post_date: (string) publish date
29
  * post_content: (string) post content
30
  * post_title: (string) post title
 
31
  * post_status: (string) post status
32
  * post_name: (string) post slug
 
 
33
  * post_type: (string) post type
34
  * post_category: (string, comma divided) slug of post categories
35
  * post_tags: (string, comma divided) name of post tags
36
- * {custom_field}: any other column labels used as custom field
 
37
 
38
  = Advanced Custom Fields plugin integrate =
39
  If advanced custom field key is exists, importer will trying to use [update_field](http://www.advancedcustomfields.com/resources/functions/update_field/) function instead of built-in add_post_meta function.
40
- How to find advanced custom field key: [Finding the field key](http://www.advancedcustomfields.com/resources/functions/update_field/#finding-the+field+key)
41
 
42
  Note: multiple value is not supported yet.
43
 
@@ -53,6 +58,8 @@ Add star and read future issues about rs-csv-importer on [GitHub](https://github
53
 
54
  == Changelog ==
55
 
 
 
56
  = 0.3 =
57
  * New feature: Advanced Custom Fields integrate.
58
  * Enhancement: Use post_id if not already present when inserting post.
1
  === Really Simple CSV Importer ===
2
  Contributors: hissy, wokamoto
3
+ Tags: importer, csv, acf
4
  Requires at least: 3.0
5
  Tested up to: 3.6.1
6
+ Stable tag: 0.4
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
17
  * Tag support
18
  * Custom field support
19
  * Adcanved Custom Fields support (beta)
20
+ * Custom Taxonomy support
21
+ * Custom Post Type support
22
 
23
  Contains CSV file sample in `/wp-content/plugins/really-simple-csv-importer/sample` directory.
24
 
29
  * post_date: (string) publish date
30
  * post_content: (string) post content
31
  * post_title: (string) post title
32
+ * post_excerpt: (string) post excerpt
33
  * post_status: (string) post status
34
  * post_name: (string) post slug
35
+ * post_parent: (int) post parent id. Used for page or hierarchical post type.
36
+ * menu_order: (int)
37
  * post_type: (string) post type
38
  * post_category: (string, comma divided) slug of post categories
39
  * post_tags: (string, comma divided) name of post tags
40
+ * {custom_field}: (string) any other column labels used as custom field
41
+ * {tax_$taxonomy}: (string, comma divided) any field prefixed with tax_ in the "custom_field" area will be used as a custom taxonomy. Taxonomy must already exist. Entries are names, not slugs
42
 
43
  = Advanced Custom Fields plugin integrate =
44
  If advanced custom field key is exists, importer will trying to use [update_field](http://www.advancedcustomfields.com/resources/functions/update_field/) function instead of built-in add_post_meta function.
45
+ How to find advanced custom field key: [Finding the field key](http://www.advancedcustomfields.com/resources/functions/update_field/#finding-the%20field%20key)
46
 
47
  Note: multiple value is not supported yet.
48
 
58
 
59
  == Changelog ==
60
 
61
+ = 0.4 =
62
+ * New feature: Added custom taxonomy support. Thanks chuckhendo!
63
  = 0.3 =
64
  * New feature: Advanced Custom Fields integrate.
65
  * Enhancement: Use post_id if not already present when inserting post.
rs-csv-importer.php CHANGED
@@ -94,10 +94,11 @@ class RS_CSV_Importer extends WP_Importer {
94
  /** Insert post and postmeta using wp_post_helper
95
  * @param array $post
96
  * @param array $meta
 
97
  * @param bool $is_update
98
  * More information: https://gist.github.com/4084471
99
  */
100
- function save_post($post,$meta,$is_update) {
101
  $ph = new wp_post_helper($post);
102
 
103
  foreach ($meta as $key => $value) {
@@ -114,6 +115,10 @@ class RS_CSV_Importer extends WP_Importer {
114
  if (!$is_acf)
115
  $ph->add_meta($key,$value,true);
116
  }
 
 
 
 
117
 
118
  if ($is_update)
119
  $result = $ph->update();
@@ -229,7 +234,7 @@ class RS_CSV_Importer extends WP_Importer {
229
  // (string, comma divided) slug of post categories
230
  $post_category = $h->get_data($this,$data,'post_category');
231
  if ($post_category) {
232
- $categories = preg_split("/[\s,]+/", $post_category);
233
  if ($categories) {
234
  $post['post_category'] = wp_create_categories($categories);
235
  }
@@ -238,20 +243,34 @@ class RS_CSV_Importer extends WP_Importer {
238
  // (string, comma divided) name of post tags
239
  $post_tags = $h->get_data($this,$data,'post_tags');
240
  if ($post_tags) {
241
- $tags = preg_split("/[\s,]+/", $post_tags);
242
  if ($tags) {
243
  $post['post_tags'] = $tags;
244
  }
245
  }
246
 
247
  $meta = array();
 
 
248
  foreach ($data as $key => $value) {
249
  if (!empty($value) && isset($this->column_keys[$key])) {
250
- $meta[$this->column_keys[$key]] = $value;
 
 
 
 
 
 
 
 
 
 
 
 
251
  }
252
  }
253
 
254
- $result = $this->save_post($post,$meta,$is_update);
255
  if (!$result) {
256
  echo '<li>'.sprintf(__('An error occurred during processing %s', 'rs-csv-importer'), esc_html($post['post_title'])).'</li>';
257
  } else {
94
  /** Insert post and postmeta using wp_post_helper
95
  * @param array $post
96
  * @param array $meta
97
+ * @param array $terms
98
  * @param bool $is_update
99
  * More information: https://gist.github.com/4084471
100
  */
101
+ function save_post($post,$meta,$terms,$is_update) {
102
  $ph = new wp_post_helper($post);
103
 
104
  foreach ($meta as $key => $value) {
115
  if (!$is_acf)
116
  $ph->add_meta($key,$value,true);
117
  }
118
+
119
+ foreach ($terms as $key => $value) {
120
+ $ph->add_terms($key, $value);
121
+ }
122
 
123
  if ($is_update)
124
  $result = $ph->update();
234
  // (string, comma divided) slug of post categories
235
  $post_category = $h->get_data($this,$data,'post_category');
236
  if ($post_category) {
237
+ $categories = preg_split("/,+/", $post_category);
238
  if ($categories) {
239
  $post['post_category'] = wp_create_categories($categories);
240
  }
243
  // (string, comma divided) name of post tags
244
  $post_tags = $h->get_data($this,$data,'post_tags');
245
  if ($post_tags) {
246
+ $tags = preg_split("/,+/", $post_tags);
247
  if ($tags) {
248
  $post['post_tags'] = $tags;
249
  }
250
  }
251
 
252
  $meta = array();
253
+ $tax = array();
254
+
255
  foreach ($data as $key => $value) {
256
  if (!empty($value) && isset($this->column_keys[$key])) {
257
+ // check if meta is custom taxonomy
258
+ if (substr($this->column_keys[$key], 0, 4) == 'tax_') {
259
+ // (string, comma divided) name of custom taxonomies
260
+ $customtaxes = preg_split("/,+/", $value);
261
+ $taxname = substr($this->column_keys[$key], 4);
262
+ $tax[$taxname] = array();
263
+ foreach($customtaxes as $key => $value ) {
264
+ $tax[$taxname][] = $value;
265
+ }
266
+ }
267
+ else {
268
+ $meta[$this->column_keys[$key]] = $value;
269
+ }
270
  }
271
  }
272
 
273
+ $result = $this->save_post($post,$meta,$tax,$is_update);
274
  if (!$result) {
275
  echo '<li>'.sprintf(__('An error occurred during processing %s', 'rs-csv-importer'), esc_html($post['post_title'])).'</li>';
276
  } else {
sample/movies.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ "post_type","post_status","post_title","post_category","tax_actors"
2
+ "post","publish","Parker","action,crime,thriller","Jason Statham,Jennifer Lopez, Michael Chiklis"
3
+ "post","publish","告白(kokuhaku)","drama, mystery","松たか子, 岡田 将生,木村佳乃"
4
+ "post","publish","The Cabin in the Woods","horror, mystery, thriller","Kristen Connolly, Chris Hemsworth, Anna Hutchison"
sample/movies.ods ADDED
Binary file
sample/pages.csv ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ "post_id","post_parent","post_type","post_status","post_title","post_content","menu_order"
2
+ ,,"page","publish","Import Page Test",,
3
+ ,2,"page",,"Child Page Test","This page is child of sample page",1
4
+ ,2,"page",,"Child Page Test 3",,3
5
+ ,2,"page",,"Child Page Test 2",,2
sample/pages.ods ADDED
Binary file