Really Simple CSV Importer - Version 0.5

Version Description

  • New feature: Added filter hooks to customize import data
  • Bug fix
Download this release

Release Info

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

Code changes from version 0.4.2 to 0.5

Files changed (2) hide show
  1. readme.txt +96 -1
  2. rs-csv-importer.php +5 -1
readme.txt CHANGED
@@ -3,7 +3,7 @@ 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.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -56,8 +56,103 @@ Add star and read future issues about rs-csv-importer on [GitHub](https://github
56
  3. Go to the Import page under Tools menu.
57
  4. Click CSV link, read the notification, then just upload and import.
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  == Changelog ==
60
 
 
 
 
61
  = 0.4.2 =
62
  * Post title bug fix
63
  = 0.4.1 =
3
  Tags: importer, csv, acf
4
  Requires at least: 3.0
5
  Tested up to: 3.6.1
6
+ Stable tag: 0.5
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
56
  3. Go to the Import page under Tools menu.
57
  4. Click CSV link, read the notification, then just upload and import.
58
 
59
+ == How to customize import rules ==
60
+
61
+ There are three filters available in the importer.
62
+
63
+ = really_simple_csv_importer_save_post =
64
+
65
+ This filter is applied to post data.
66
+
67
+ Parameters:
68
+
69
+ * $post - (array)(required) post data
70
+ * $is_update (bool) update existing post data, or insert new post data
71
+
72
+ Example:
73
+
74
+ `
75
+ function really_simple_csv_importer_save_post_filter( $post, $is_update ) {
76
+
77
+ // remove specific tag from import data
78
+ if (isset($post['post_tags'])) {
79
+ $_tags = array();
80
+ foreach ($post['post_tags'] as $tag) {
81
+ if ($tag != 'Apple') {
82
+ $_tags[] = $tag;
83
+ }
84
+ }
85
+ $post['post_tags'] = $_tags;
86
+ }
87
+
88
+ return $post;
89
+ }
90
+ add_filter( 'really_simple_csv_importer_save_post', 'really_simple_csv_importer_save_post_filter', 10, 2 );
91
+ `
92
+
93
+ = really_simple_csv_importer_save_meta =
94
+
95
+ This filter is applied to post meta data.
96
+
97
+ Parameters:
98
+
99
+ * $meta - (array)(required) post meta data
100
+ * $post - (array) post data
101
+ * $is_update (bool)
102
+
103
+ Example:
104
+
105
+ `
106
+ function really_simple_csv_importer_save_meta_filter( $meta, $post, $is_update ) {
107
+
108
+ // serialize metadata
109
+ $meta_array = array();
110
+ if (isset($meta['meta_key_1'])) $meta_array[] = $meta['meta_key_1'];
111
+ if (isset($meta['meta_key_2'])) $meta_array[] = $meta['meta_key_2'];
112
+ $meta = array( 'meta_key' => $meta_array );
113
+
114
+ return $meta;
115
+ }
116
+ add_filter( 'really_simple_csv_importer_save_meta', 'really_simple_csv_importer_save_meta_filter', 10, 3 );
117
+ `
118
+
119
+ = really_simple_csv_importer_save_tax =
120
+
121
+ This filter is applied to post taxonomy data (categories and tags are not included, these are post data).
122
+
123
+ Parameters:
124
+
125
+ * $tax - (array)(required) post taxonomy data
126
+ * $post - (array) post data
127
+ * $is_update (bool)
128
+
129
+ Example:
130
+
131
+ `
132
+ function really_simple_csv_importer_save_tax_filter( $tax, $post, $is_update ) {
133
+
134
+ // Fix misspelled taxonomy
135
+ if (isset($tax['actors'])) {
136
+ $_actors = array();
137
+ foreach ($tax['actors'] as $actor) {
138
+ if ($actor == 'Johnny Dep') {
139
+ $actor = 'Johnny Depp';
140
+ }
141
+ $_actors[] = $actor;
142
+ }
143
+ $tax['actors'] = $_actors;
144
+ }
145
+
146
+ return $tax;
147
+ }
148
+ add_filter( 'really_simple_csv_importer_save_tax', 'really_simple_csv_importer_save_tax_filter', 10, 3 );
149
+ `
150
+
151
  == Changelog ==
152
 
153
+ = 0.5 =
154
+ * New feature: Added filter hooks to customize import data
155
+ * Bug fix
156
  = 0.4.2 =
157
  * Post title bug fix
158
  = 0.4.1 =
rs-csv-importer.php CHANGED
@@ -7,7 +7,7 @@ Author: Takuro Hishikawa, wokamoto
7
  Author URI: http://notnil-creative.com/
8
  Text Domain: rs-csv-importer
9
  License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10
- Version: 0.4.2
11
  */
12
 
13
  if ( !defined('WP_LOAD_IMPORTERS') )
@@ -273,6 +273,10 @@ class RS_CSV_Importer extends WP_Importer {
273
  }
274
  }
275
 
 
 
 
 
276
  $result = $this->save_post($post,$meta,$tax,$is_update);
277
  if (!$result) {
278
  echo '<li>'.sprintf(__('An error occurred during processing %s', 'rs-csv-importer'), esc_html($post_title)).'</li>';
7
  Author URI: http://notnil-creative.com/
8
  Text Domain: rs-csv-importer
9
  License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10
+ Version: 0.5
11
  */
12
 
13
  if ( !defined('WP_LOAD_IMPORTERS') )
273
  }
274
  }
275
 
276
+ $post = apply_filters( 'really_simple_csv_importer_save_post', $post, $is_update );
277
+ $meta = apply_filters( 'really_simple_csv_importer_save_meta', $meta, $post, $is_update );
278
+ $tax = apply_filters( 'really_simple_csv_importer_save_tax', $tax, $post, $is_update );
279
+
280
  $result = $this->save_post($post,$meta,$tax,$is_update);
281
  if (!$result) {
282
  echo '<li>'.sprintf(__('An error occurred during processing %s', 'rs-csv-importer'), esc_html($post_title)).'</li>';