Ultimate CSV Importer - Version 2.5.0

Version Description

Download this release

Release Info

Developer smackcoders
Plugin Icon 128x128 Ultimate CSV Importer
Version 2.5.0
Comparing to
See all releases

Code changes from version 2.0.0 to 2.5.0

Readme.txt CHANGED
@@ -1,11 +1,11 @@
1
- === Wp Ultimate CSV Importer Plugin ===
2
  Contributors: Smackcoders
3
  Donate link: http://www.smackcoders.com/donate.html
4
  Tags: batch, excel, import, spreadsheet, plugin, admin, csv, importer,
5
  Requires at least: 3.4
6
- Tested up to: 3.4.2
7
- Stable tag: 2.0.0
8
- Version: 2.0.0
9
  Author: Smackcoders
10
  Author URI: http://profiles.wordpress.org/smackcoders/
11
  License: GPLv2 or later
@@ -15,7 +15,7 @@ A plugin that helps to import any csv file as post, page or custom post data's b
15
 
16
  == Description ==
17
 
18
- Wp Ultimate CSV Importer Plugin helps you to import any csv file as post, page or even as custom post data's by matching its headers to relevant fields or custom fields.
19
 
20
  1. Admin can import the data's from any csv file.
21
  2. Can define the type of post and post status while importing.
@@ -25,6 +25,8 @@ Wp Ultimate CSV Importer Plugin helps you to import any csv file as post, page o
25
  6. Make imported post as published or make it as draft.
26
  7. Added featured image import functionality.
27
 
 
 
28
  Important Note: To import your posts for scheduled publishing in future, have a date coloumn in your csv with the date of post to be published on. If the date is a future date, then the post will be automatically scheduled for publishing on particular date as mentioned in csv.
29
 
30
  Note: Your theme should support featured image function. If not, please add the following code to header.php or where it needed.
@@ -34,96 +36,90 @@ You can follow the instructions as given here
34
  [http://codex.wordpress.org/Function_Reference/the_post_thumbnail](http://codex.wordpress.org/Function_Reference/the_post_thumbnail)
35
  [http://codex.wordpress.org/Post_Thumbnails](http://codex.wordpress.org/Post_Thumbnails) [http://wordpress.org/support/topic/featured-image-not-showing-7?replies=5](http://wordpress.org/support/topic/featured-image-not-showing-7?replies=5)
36
 
 
 
 
 
 
 
 
 
37
 
38
  Support and Feature request.
39
  ----------------------------
40
 
41
- Please create issues only in our tracker http://code.smackcoders.com/wp-csv-importer/issues instead of wordpress support forum.
42
 
43
- For guides and tutorials, visit http://www.smackcoders.com/category/free-wordpress-plugins/google-seo-author-snippet-plugin.html .
44
 
45
 
46
 
47
  == Installation ==
48
 
49
 
50
- Wp Ultimate CSV Importer is very easy to install like any other wordpress plugin. No need to edit or modify anything here.
51
-
52
- 1. Unzip the file 'wp-ultimate-csv-importer.zip'.
53
- 2. Upload the ' wp-ultimate-csv-importer ' directory to '/wp-content/plugins/' directory using ftp client or upload and install
54
- wp-ultimate-csv-importer.zip through plugin install wizard in wp admin panel
55
- 3. Activate the plugin through the 'Plugins' menu in WordPress.
56
- 4. After activating, you will see an option for 'Wp Ultimate CSV Importer' in the admin menu (left navigation) and you will import the csv files to import the data's.
57
 
58
 
59
 
60
  == Screenshots ==
61
 
62
- 1. Admin settings for Wp Ultimate CSV Importer Plugin .
63
  2. Admin settings for Import Data and Header Mapping configuration to import data's from a csv file.
64
 
65
 
66
 
67
  == Changelog ==
68
 
69
- = 2.0.0 = WPDEBUG errors fixed. CSV import folder changed to Wp native uploads folder.
70
 
71
- = 1.1.1 = Renamed the mapping field attachment as featured_image and category as post_category.
72
 
73
- = 1.1.0 = Added featured image import feature along with post/page/custom post.
74
 
75
- = 1.0.2 = - Bug fixed to recognize the trimmed trailing space in the CSV file
76
- - Added validation for the duplicate field mapping.
77
 
78
- = 1.0.1 = Added features to import multiple tags and categories with different delimiters.
79
 
80
- = 1.0.0 = Initial release version. Tested and found works well without any issues.
 
81
 
 
82
 
 
83
 
84
 
85
- == Upgrade Notice ==
86
 
87
- =v 2.0.0= Major Bug fixed and should upgrade. WPDEBUG errors fixed. CSV import folder changed to Wp native uploads folder.
88
 
89
- =v 1.1.1 = Minor correction and fix applied.
90
 
91
- =v 1.1.0 = A major new feature added in this version. Update needed.
 
 
 
 
92
 
93
- =v 1.0.2 = This version have important bug fixes and newly added features. Must be upgrade immediately.
94
 
95
- =v 1.0.1 = Added features to import multiple tags and categories with different delimiters.
96
 
97
- =v 1.0.0 = Initial release of plugin.
98
 
 
99
 
 
100
 
 
101
 
102
- == Frequently Asked Questions ==
103
 
104
- 1. How to install the plugin?
105
 
106
- Like other plugins wp-ultimate-csv-importer is easy to install. Upload the wp-ultimate-csv-importer.zip file through plugin install page through wp admin. Everything will work fine with it.
107
-
108
- 2. How to use the plugin?
109
 
110
- After plugin activation you can see the ' Wp Ultimate CSV Importer ' menu in admin backend.
111
-
112
- a. Browse csv file to import the data's.
113
- b. Select the post type or post / page to import as.
114
- b. Map each header to the relevant fields using the drop downs to import.
115
- c. If import as draft option is checked, post will be in draft mode.
116
-
117
- 3. How to define the multiple tags and categories?
118
 
119
- In CSV, tags should be separated by "," to import multiple tags and categories should be separated by "|" to import multiple categories.
120
-
121
- 4. How to choose featured image to import?
122
- Match the coloumn contains url paths to images to Attachment field from the drop down.
123
 
124
- Configuring our plugin is as simple as that.
125
 
126
- For quick response and reply please create issues in our [support](http://code.smackcoders.com/wp-csv-importer/issues) instead of wordpress support forum.
127
 
128
 
129
 
1
+ === WP Ultimate CSV Importer Plugin ===
2
  Contributors: Smackcoders
3
  Donate link: http://www.smackcoders.com/donate.html
4
  Tags: batch, excel, import, spreadsheet, plugin, admin, csv, importer,
5
  Requires at least: 3.4
6
+ Tested up to: 3.5.1
7
+ Stable tag: 2.5.0
8
+ Version: 2.5.0
9
  Author: Smackcoders
10
  Author URI: http://profiles.wordpress.org/smackcoders/
11
  License: GPLv2 or later
15
 
16
  == Description ==
17
 
18
+ WP Ultimate CSV Importer Plugin helps you to import any csv file as post, page or even as custom post data's by matching its headers to relevant fields or custom fields.
19
 
20
  1. Admin can import the data's from any csv file.
21
  2. Can define the type of post and post status while importing.
25
  6. Make imported post as published or make it as draft.
26
  7. Added featured image import functionality.
27
 
28
+ The pro version of this plugin is available now with lot more new features, functionalities, controls and usability. Please upgrade to pro version to enjoy the powerful features like importing nested categories, WP-e-commerce products, eShop products, custom taxonomies in bulk with simple clicks.
29
+
30
  Important Note: To import your posts for scheduled publishing in future, have a date coloumn in your csv with the date of post to be published on. If the date is a future date, then the post will be automatically scheduled for publishing on particular date as mentioned in csv.
31
 
32
  Note: Your theme should support featured image function. If not, please add the following code to header.php or where it needed.
36
  [http://codex.wordpress.org/Function_Reference/the_post_thumbnail](http://codex.wordpress.org/Function_Reference/the_post_thumbnail)
37
  [http://codex.wordpress.org/Post_Thumbnails](http://codex.wordpress.org/Post_Thumbnails) [http://wordpress.org/support/topic/featured-image-not-showing-7?replies=5](http://wordpress.org/support/topic/featured-image-not-showing-7?replies=5)
38
 
39
+ The pro version of ultimate csv importer plugin have many more features like
40
+
41
+ Bulk products import for WP-e-commerce plugin in few clicks.
42
+ Bulk products import for eShop plugin in few clicks.
43
+ Custom Taxonomy
44
+ Bulk Nested Categories import.
45
+
46
+ Upgrade to pro for these powerful features.
47
 
48
  Support and Feature request.
49
  ----------------------------
50
 
51
+ Please create issues only in our tracker http://forge.smackcoders.com/projects/wp-ultimate-csv-importer-free/issues instead of WordPress support forum.
52
 
53
+ For guides and tutorials, visit http://forge.smackcoders.com/projects/wp-ultimate-csv-importer-free .
54
 
55
 
56
 
57
  == Installation ==
58
 
59
 
60
+ Please click here for [Detailed Installation Instructions](http://www.smackcoders.com/blog/category/free-wordpress-plugins/wordpress-ultimate-csv-importer-plugin/)
 
 
 
 
 
 
61
 
62
 
63
 
64
  == Screenshots ==
65
 
66
+ 1. Admin settings for WP Ultimate CSV Importer Plugin .
67
  2. Admin settings for Import Data and Header Mapping configuration to import data's from a csv file.
68
 
69
 
70
 
71
  == Changelog ==
72
 
73
+ = 2.5.0 = Major issues fixed and updated to WordPress-3.5.1 compatibility.
74
 
75
+ = 2.0.1 = Update to WordPress-3.5 compatibility.
76
 
77
+ = 2.0.0 = WPDEBUG errors fixed. CSV import folder changed to WP native uploads folder.
78
 
79
+ = 1.1.1 = Renamed the mapping field attachment as featured_image and category as post_category.
 
80
 
81
+ = 1.1.0 = Added featured image import feature along with post/page/custom post.
82
 
83
+ = 1.0.2 = - Bug fixed to recognize the trimmed trailing space in the CSV file
84
+ - Added validation for the duplicate field mapping.
85
 
86
+ = 1.0.1 = Added features to import multiple tags and categories with different delimiters.
87
 
88
+ = 1.0.0 = Initial release version. Tested and found works well without any issues.
89
 
90
 
 
91
 
 
92
 
93
+ == Upgrade Notice ==
94
 
95
+ =v 2.5.0 = Major issues fixed and updated to WordPress-3.5.1 compatibility.
96
+ -- Duplicate detection added.
97
+ -- Added more information in success message.
98
+ -- Import memory issues solved.
99
+ -- Fixed scandinavian character conflicts.
100
 
101
+ =v 2.0.1 = Update to WordPress-3.5 compatibility.
102
 
103
+ =v 2.0.0 = Major Bug fixed and should upgrade. WPDEBUG errors fixed. CSV import folder changed to WP native uploads folder.
104
 
105
+ =v 1.1.1 = Minor correction and fix applied.
106
 
107
+ =v 1.1.0 = A major new feature added in this version. Update needed.
108
 
109
+ =v 1.0.2 = This version have important bug fixes and newly added features. Must be upgrade immediately.
110
 
111
+ =v 1.0.1 = Added features to import multiple tags and categories with different delimiters.
112
 
113
+ =v 1.0.0 = Initial release of plugin.
114
 
 
115
 
 
 
 
116
 
 
 
 
 
 
 
 
 
117
 
118
+ == Frequently Asked Questions ==
 
 
 
119
 
120
+ Please click here for [ Detailed Frequently Asked Questions](http://www.smackcoders.com/blog/category/free-wordpress-plugins/wordpress-ultimate-csv-importer-plugin/)
121
 
122
+ For quick response and reply please create issues in our [support](http://forge.smackcoders.com/projects/wp-ultimate-csv-importer-free/issues) instead of WordPress support forum.
123
 
124
 
125
 
images/icon.png ADDED
Binary file
wp_ultimate_csv_importer.js CHANGED
@@ -1,10 +1,8 @@
1
-
2
  // Function for add customfield
3
-
4
  function addcustomfield(myval,selected_id){
5
  var a = document.getElementById('h1').value;
6
  var aa = document.getElementById('h2').value;
7
- var selected_value;// added at version 1.0.2 by fredrick
8
  for(var i=0;i<aa;i++){
9
  var b = document.getElementById('mapping'+i).value;
10
  if(b=='add_custom'+i){
@@ -14,7 +12,6 @@ function addcustomfield(myval,selected_id){
14
  document.getElementById('textbox'+i).style.display="none";
15
  }
16
  }
17
- // Code Added at version 1.0.2 by fredrick
18
  var header_count = document.getElementById('h2').value;
19
  for(var j=0;j<header_count;j++){
20
  var selected_value = document.getElementById('mapping'+j);
@@ -30,10 +27,10 @@ function addcustomfield(myval,selected_id){
30
  }
31
 
32
  // Function for check file exist
33
-
34
  function file_exist(){
35
 
36
  if(document.getElementById('csv_import').value==''){
 
37
  return false;
38
  }
39
  else{
@@ -41,10 +38,7 @@ function file_exist(){
41
  }
42
  }
43
 
44
- // Code added at version 1.0.2 by fredrick
45
-
46
  // Function for import csv
47
-
48
  function import_csv(){
49
  var header_count = document.getElementById('h2').value;
50
  var array = new Array();
@@ -67,7 +61,7 @@ function import_csv(){
67
  return true;
68
  }
69
  else{
70
- alert('"post_type" and "post_content" should be mapped.');
71
  return false;
72
  }
73
  }
 
1
  // Function for add customfield
 
2
  function addcustomfield(myval,selected_id){
3
  var a = document.getElementById('h1').value;
4
  var aa = document.getElementById('h2').value;
5
+ var selected_value;
6
  for(var i=0;i<aa;i++){
7
  var b = document.getElementById('mapping'+i).value;
8
  if(b=='add_custom'+i){
12
  document.getElementById('textbox'+i).style.display="none";
13
  }
14
  }
 
15
  var header_count = document.getElementById('h2').value;
16
  for(var j=0;j<header_count;j++){
17
  var selected_value = document.getElementById('mapping'+j);
27
  }
28
 
29
  // Function for check file exist
 
30
  function file_exist(){
31
 
32
  if(document.getElementById('csv_import').value==''){
33
+ alert('Please attach your csv');
34
  return false;
35
  }
36
  else{
38
  }
39
  }
40
 
 
 
41
  // Function for import csv
 
42
  function import_csv(){
43
  var header_count = document.getElementById('h2').value;
44
  var array = new Array();
61
  return true;
62
  }
63
  else{
64
+ alert('"post_title" and "post_content" should be mapped.');
65
  return false;
66
  }
67
  }
wp_ultimate_csv_importer.php CHANGED
@@ -1,9 +1,9 @@
1
  <?php
2
  /*
3
- *Plugin Name: Wp Ultimate CSV Importer
4
  *Plugin URI: http://www.smackcoders.com/category/free-wordpress-plugins.html
5
  *Description: A plugin that helps to import the data's from a CSV file.
6
- *Version: 2.0.0
7
  *Author: smackcoders.com
8
  *Author URI: http://www.smackcoders.com
9
  *
@@ -23,10 +23,15 @@
23
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
  *
25
  * @link http://www.smackcoders.com/category/free-wordpress-plugins.html
26
-
27
  ***********************************************************************************************
28
  */
29
 
 
 
 
 
 
 
30
  $upload_dir = wp_upload_dir();
31
  $importdir = $upload_dir['basedir']."/imported_csv/";
32
  if(!is_dir($importdir))
@@ -43,6 +48,8 @@ global $defaults;
43
  global $wpdb;
44
  global $keys;
45
  global $delim;
 
 
46
  # Code added by goku
47
  $delim = empty($_POST['delim']) ? '' : $_POST['delim'];
48
  // Get the custom fields
@@ -54,13 +61,14 @@ $keys = $wpdb->get_col( "
54
  HAVING meta_key NOT LIKE '\_%'
55
  ORDER BY meta_key
56
  LIMIT $limit" );
 
57
  // Default header array
58
- // Code modified at version 1.1.1 by fredrick
59
  $defaults = array(
60
  'post_title' => null,
61
  'post_content' => null,
62
  'post_excerpt' => null,
63
  'post_date' => null,
 
64
  'post_tag' => null,
65
  'post_category' => null,
66
  'post_author' => null,
@@ -71,27 +79,25 @@ foreach($keys as $val){
71
  $defaults[$val]=$val;
72
  }
73
  // Admin menu settings
74
- function wp_ultimate_csv_importer() {
75
- add_menu_page('CSV importer settings', 'Wp Ultimate CSV Importer', 'manage_options',
76
- 'upload_csv_file', 'upload_csv_file');
 
77
  }
78
 
79
- # Code added by goku -- Starts here --
80
-
81
  function LoadWpScript()
82
  {
83
- wp_register_script('wp_ultimate_scripts', site_url()."/wp-content/plugins/wp-ultimate-csv-importer/wp_ultimate_csv_importer.js", array("jquery"));
 
84
  wp_enqueue_script('wp_ultimate_scripts');
85
  }
86
  add_action('admin_enqueue_scripts', 'LoadWpScript');
87
-
88
- # -- Code ends here --
89
-
90
  add_action("admin_menu", "wp_ultimate_csv_importer");
91
 
92
  // Plugin description details
93
  function description(){
94
- $string = "<p>Wp Ultimate CSV Importer Plugin helps you to manage the post,page and </br> custom post data's from a CSV file.</p>
 
95
  <p>
96
  1. Admin can import the data's from any csv file.
97
  </p>
@@ -110,9 +116,12 @@ function description(){
110
  <p>
111
  6. Make imported post as published or make it as draft.
112
  </p>
113
- <p>Configuring our plugin is as simple as that. If you have any questions, issues and request on new features, plaese visit <a href='http://www.smackcoders.com/category/free-wordpress-plugins.html' target='_blank'>Smackcoders.com Blog </a></p>
 
 
 
114
 
115
- <div align='center' style='margin-top:40px;'> 'While the scripts on this site are free, donations are greatly appreciated. '<br/><br/><a href='http://www.smackcoders.com/donate.html' target='_blank'><img src='".site_url()."/wp-content/plugins/wp-ultimate-csv-importer/images/paypal_donate_button.png' /></a><br/><br/><a href='http://www.smackcoders.com/' target='_blank'><img src='http://www.smackcoders.com/wp-content/uploads/2012/09/Smack_poweredby_200.png'></a>
116
  </div><br/>";
117
  return $string;
118
  }
@@ -144,7 +153,7 @@ function move_file()
144
  {
145
  # Code added by goku
146
  $upload_dir = wp_upload_dir();
147
- $uploads_dir = $upload_dir['basedir']."/imported_csv/";
148
  if ($_FILES["csv_import"]["error"] == 0) {
149
  $tmp_name = $_FILES["csv_import"]["tmp_name"];
150
  $name = $_FILES["csv_import"]["name"];
@@ -162,6 +171,20 @@ function fileDelete($filepath,$filename) {
162
  return $success;
163
  }
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  // Mapping the fields and upload data's
166
  function upload_csv_file()
167
  {
@@ -171,6 +194,7 @@ function upload_csv_file()
171
  global $keys;
172
  global $custom_array;
173
  global $delim;
 
174
  # Code added by goku
175
  $upload_dir = wp_upload_dir();
176
  $importdir = $upload_dir['basedir']."/imported_csv/";
@@ -180,7 +204,9 @@ function upload_csv_file()
180
  csv_file_data($_FILES['csv_import']['tmp_name'],$delim);
181
  move_file();
182
  ?>
183
- <div style="background-color: #FFFFE0;border-color: #E6DB55;border-radius: 3px 3px 3px 3px;border-style: solid;border-width: 1px;margin: 5px 15px 2px; margin-top:15px;padding: 5px;text-align:center"> Please check out <a href="http://smackcoders.com/category/free-wordpress-plugins.html" target="_blank">www.smackcoders.com</a> for the latest news and details of other great plugins and tools. </div><br/>
 
 
184
  <?php if ( count($headers)>=1 && count($data_rows)>=1 ){?>
185
  <div style="float:left;min-width:45%">
186
  <form class="add:the-list: validate" method="post" onsubmit="return import_csv();">
@@ -194,7 +220,7 @@ function upload_csv_file()
194
  <?php
195
  $post_types=get_post_types();
196
  foreach($post_types as $key => $value){
197
- if(($value!='featured_image') && ($value!='revision') && ($value!='nav_menu_item')){ ?>
198
  <option id="<?php echo($value);?>" name="<?php echo($value);?>"> <?php echo($value);?> </option>
199
  <?php }
200
  }
@@ -224,7 +250,12 @@ function upload_csv_file()
224
  foreach($defaults as $key1=>$value1){
225
  ?>
226
  <option value ="<?php print($key1);?>"><?php print($key1);?></option>
227
- <?php }
 
 
 
 
 
228
  ?>
229
  <option value="add_custom<?php print($count);?>">Add Custom Field</option>
230
  </select>
@@ -237,7 +268,7 @@ function upload_csv_file()
237
  </table>
238
  </div><br/>
239
  <input type='hidden' name='filename' id='filename' value="<?php echo($_FILES['csv_import']['name']);?>" />
240
- <input type='submit' name= 'post_csv' id='post_csv' value='Import' />
241
  </form>
242
  </div>
243
  <div style="min-width:45%;">
@@ -250,7 +281,7 @@ function upload_csv_file()
250
  </div><br/>
251
  <div style="margin-left:20px;">
252
  <form class="add:the-list: validate" method="post" action="">
253
- <input type="submit" class="button" name="Import Again" value="Import Again"/>
254
  </form>
255
  </div>
256
  <div style="margin-left:20px;margin-top:30px;">
@@ -262,6 +293,8 @@ function upload_csv_file()
262
  }
263
  else if(isset($_POST['post_csv']))
264
  {
 
 
265
  # Code added by goku
266
  $upload_dir = wp_upload_dir();
267
  $dir = $upload_dir['basedir']."/imported_csv/";
@@ -292,12 +325,25 @@ function upload_csv_file()
292
  }
293
  }
294
  foreach($new_post as $ckey => $cval){
295
- if($ckey!='post_category' && $ckey!='post_tag' && $ckey!='featured_image'){ // Code modified at version 1.0.2 by fredrick
 
 
 
 
 
 
 
 
296
  if(array_key_exists($ckey,$custom_array)){
297
  $darray[$ckey]=$new_post[$ckey];
298
  }
299
  else{
300
- $data_array[$ckey]=$new_post[$ckey];
 
 
 
 
 
301
  }
302
  }
303
  else{
@@ -307,7 +353,7 @@ function upload_csv_file()
307
  if($ckey == 'post_category'){
308
  $categories[$ckey]=$new_post[$ckey];
309
  }
310
- if($ckey == 'featured_image'){ // Code added at version 1.1.0 by fredrick
311
  $file_url=$filetype[$ckey]=$new_post[$ckey];
312
  $file_type = explode('.',$filetype[$ckey]);
313
  $count = count($file_type);
@@ -334,16 +380,21 @@ function upload_csv_file()
334
  $filepath = $full_path.'/'.$filename[$file_split-1];
335
  $fileurl = $baseurl.'/'.$filename[$file_split-1];
336
  if(is_dir($full_path)){
337
- copy($file_url,$filepath);
338
  }
339
  else{
340
  wp_mkdir_p($full_path);
341
- copy($file_url,$filepath);
 
 
 
 
 
 
 
 
 
342
  }
343
- $file['guid']=$fileurl;
344
- $file['post_title']=$img_title;
345
- $file['post_content']='';
346
- $file['post_status']='inherit';
347
  }
348
  }
349
  }
@@ -352,53 +403,77 @@ function upload_csv_file()
352
  $data_array['post_status']='draft';
353
  }
354
  $data_array['post_type']=$_POST['csv_importer_cat'];
355
- $post_id = wp_insert_post( $data_array );
356
- if(!empty($custom_array)){
357
- foreach($custom_array as $custom_key => $custom_value){
358
- add_post_meta($post_id, $custom_key, $custom_value);
359
- }
360
- }
361
 
362
- // Create/Add tags to post
363
- if(!empty($tags)){
364
- foreach($tags as $tag_key => $tag_value){
365
- wp_set_post_tags( $post_id, $tag_value );
366
- }
367
- } // End of code to add tags
368
 
369
- // Create/Add category to post
370
- if(!empty($categories)){
371
- $split_line = explode('|',$categories['post_category']);
372
- wp_set_object_terms($post_id, $split_line, 'category');
 
 
 
 
 
 
373
 
374
- } // End of code to add category
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375
 
376
- // Code added to import featured image at version 1.1.0 by fredrick
377
- if(!empty($file)){
378
- $file_name=$dirname.'/'.$img_title.'.'.$type;
379
- $attach_id = wp_insert_attachment($file, $file_name, $post_id);
380
- require_once(ABSPATH . 'wp-admin/includes/image.php');
381
- $attach_data = wp_generate_attachment_metadata( $attach_id, $fileurl );
382
- wp_update_attachment_metadata( $attach_id, $attach_data );
383
- //add_post_meta($post_id, '_thumbnail_id', $attach_id, true);
384
- set_post_thumbnail( $post_id, $attach_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  }
386
  }
387
  ?>
388
- <div style="background-color: #FFFFE0;border-color: #E6DB55;border-radius: 3px 3px 3px 3px;border-style: solid;border-width: 1px;margin: 5px 15px 2px; padding: 5px;text-align:center"><b> Successfully Imported ! </b></div>
389
  <div style="margin-top:30px;margin-left:10px">
390
  <form class="add:the-list: validate" method="post" enctype="multipart/form-data">
391
- <input type="submit" id="goto" name="goto" value="Continue" />
392
  </form>
393
  </div>
394
  <?php
395
- // Code modified at version 1.1.2
396
- // Remove CSV file
397
  $upload_dir = wp_upload_dir();
398
  $csvdir = $upload_dir['basedir']."/imported_csv/";
399
  $CSVfile = $_POST['filename'];
400
  if(file_exists($csvdir.$CSVfile)){
401
- chmod("$csvdir"."$CSVfile", 755);
402
  fileDelete($csvdir,$CSVfile);
403
  }
404
  }
@@ -406,9 +481,10 @@ function upload_csv_file()
406
  {
407
  ?>
408
  <div class="wrap">
409
- <div style="background-color: #FFFFE0;border-color: #E6DB55;border-radius: 3px 3px 3px 3px;border-style: solid;border-width: 1px;margin: 5px 15px 2px; margin-top:15px;padding: 5px;text-align:center"> Please check out <a href="http://smackcoders.com/category/free-wordpress-plugins.html" target="_blank">www.smackcoders.com</a> for the latest news and details of other great plugins and tools. </div><br/>
 
410
  <div style="min-width:45%;float:left;height:500px;">
411
- <h2>Import CSV</h2>
412
  <form class="add:the-list: validate" method="post" enctype="multipart/form-data" onsubmit="return file_exist();">
413
 
414
  <!-- File input -->
@@ -420,7 +496,8 @@ function upload_csv_file()
420
  <option value=";">;</option>
421
  </select>
422
  </p>
423
- <p class="submit"><input type="submit" class="button" name="Import" value="Import" /></p>
 
424
  </form>
425
  </div>
426
  <div style="min-width:45%;">
1
  <?php
2
  /*
3
+ *Plugin Name: WP Ultimate CSV Importer
4
  *Plugin URI: http://www.smackcoders.com/category/free-wordpress-plugins.html
5
  *Description: A plugin that helps to import the data's from a CSV file.
6
+ *Version: 2.5.0
7
  *Author: smackcoders.com
8
  *Author URI: http://www.smackcoders.com
9
  *
23
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
  *
25
  * @link http://www.smackcoders.com/category/free-wordpress-plugins.html
 
26
  ***********************************************************************************************
27
  */
28
 
29
+ #Credits to Fredrick Marks
30
+ # php.ini overriding values for import a big csv file
31
+ ini_set('max_execution_time', 700);
32
+ ini_set('memory_limit', '128M');
33
+
34
+ require( dirname(__FILE__) . '/../../../wp-load.php' );
35
  $upload_dir = wp_upload_dir();
36
  $importdir = $upload_dir['basedir']."/imported_csv/";
37
  if(!is_dir($importdir))
48
  global $wpdb;
49
  global $keys;
50
  global $delim;
51
+ global $contentUrl;
52
+ $contentUrl = WP_CONTENT_URL;
53
  # Code added by goku
54
  $delim = empty($_POST['delim']) ? '' : $_POST['delim'];
55
  // Get the custom fields
61
  HAVING meta_key NOT LIKE '\_%'
62
  ORDER BY meta_key
63
  LIMIT $limit" );
64
+
65
  // Default header array
 
66
  $defaults = array(
67
  'post_title' => null,
68
  'post_content' => null,
69
  'post_excerpt' => null,
70
  'post_date' => null,
71
+ 'post_name' => null,
72
  'post_tag' => null,
73
  'post_category' => null,
74
  'post_author' => null,
79
  $defaults[$val]=$val;
80
  }
81
  // Admin menu settings
82
+ function wp_ultimate_csv_importer() {
83
+ global $contentUrl;
84
+ add_menu_page('CSV importer settings', 'WP Ultimate CSV Importer', 'manage_options',
85
+ 'upload_csv_file', 'upload_csv_file', $contentUrl."/plugins/wp-ultimate-csv-importer/images/icon.png");
86
  }
87
 
 
 
88
  function LoadWpScript()
89
  {
90
+ global $contentUrl;
91
+ wp_register_script('wp_ultimate_scripts', $contentUrl."/plugins/wp-ultimate-csv-importer/wp_ultimate_csv_importer.js", array("jquery"));
92
  wp_enqueue_script('wp_ultimate_scripts');
93
  }
94
  add_action('admin_enqueue_scripts', 'LoadWpScript');
 
 
 
95
  add_action("admin_menu", "wp_ultimate_csv_importer");
96
 
97
  // Plugin description details
98
  function description(){
99
+ global $contentUrl;
100
+ $string = "<p>WP Ultimate CSV Importer Plugin helps you to manage the post,page and </br> custom post data's from a CSV file.</p>
101
  <p>
102
  1. Admin can import the data's from any csv file.
103
  </p>
116
  <p>
117
  6. Make imported post as published or make it as draft.
118
  </p>
119
+ <p>
120
+ 7. Added featured image import functionality.
121
+ </p>
122
+ <p>Configuring our plugin is as simple as that. If you have any questions, issues and request on new features, plaese visit <a href='http://www.smackcoders.com/blog/category/free-wordpress-plugins' target='_blank'>Smackcoders.com blog </a></p>
123
 
124
+ <div align='center' style='margin-top:40px;'> 'While the scripts on this site are free, donations are greatly appreciated. '<br/><br/><a href='http://www.smackcoders.com/donate.html' target='_blank'><img src='".$contentUrl."/plugins/wp-ultimate-csv-importer/images/paypal_donate_button.png' /></a><br/><br/><a href='http://www.smackcoders.com/' target='_blank'><img src='http://www.smackcoders.com/wp-content/uploads/2012/09/Smack_poweredby_200.png'></a>
125
  </div><br/>";
126
  return $string;
127
  }
153
  {
154
  # Code added by goku
155
  $upload_dir = wp_upload_dir();
156
+ $uploads_dir = $upload_dir['basedir']."/imported_csv";
157
  if ($_FILES["csv_import"]["error"] == 0) {
158
  $tmp_name = $_FILES["csv_import"]["tmp_name"];
159
  $name = $_FILES["csv_import"]["name"];
171
  return $success;
172
  }
173
 
174
+ // Scandinavian characters
175
+ function smack_marks_scandiConverter($text){
176
+ $returnvalue="";
177
+ for($i=0;$i<strlen($text);$i++){
178
+ $smacker=hexdec(rawurlencode(substr($text, $i, 1)));
179
+ if($smacker<32||$smacker>1114111){
180
+ $returnvalue.=substr($text, $i, 1);
181
+ }else{
182
+ $returnvalue.="&#".$smacker.";";
183
+ }
184
+ }
185
+ return $returnvalue;
186
+ }
187
+
188
  // Mapping the fields and upload data's
189
  function upload_csv_file()
190
  {
194
  global $keys;
195
  global $custom_array;
196
  global $delim;
197
+ global $wpdb;
198
  # Code added by goku
199
  $upload_dir = wp_upload_dir();
200
  $importdir = $upload_dir['basedir']."/imported_csv/";
204
  csv_file_data($_FILES['csv_import']['tmp_name'],$delim);
205
  move_file();
206
  ?>
207
+ <br/>
208
+ <marquee onmouseover="this.setAttribute('scrollamount', 0, 0);" onmouseout="this.setAttribute('scrollamount', 6, 0);" >Now the <a href="http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html" target="_blank">Pro Version</a> is Available. For more details,please visit <a href="http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html" target="_blank">here</a></marquee>
209
+ <div style="background-color: #FFFFE0;border-color: #E6DB55;border-radius: 3px 3px 3px 3px;border-style: solid;border-width: 1px;margin: 5px 15px 2px; margin-top:15px;padding: 5px;text-align:center"> Please check out <a href="http://www.smackcoders.com/blog/category/free-wordpress-plugins" target="_blank">www.smackcoders.com</a> for the latest news and details of other great plugins and tools. </div><br/>
210
  <?php if ( count($headers)>=1 && count($data_rows)>=1 ){?>
211
  <div style="float:left;min-width:45%">
212
  <form class="add:the-list: validate" method="post" onsubmit="return import_csv();">
220
  <?php
221
  $post_types=get_post_types();
222
  foreach($post_types as $key => $value){
223
+ if(($value!='featured_image') && ($value!='attachment') && ($value!='revision') && ($value!='nav_menu_item')){ ?>
224
  <option id="<?php echo($value);?>" name="<?php echo($value);?>"> <?php echo($value);?> </option>
225
  <?php }
226
  }
250
  foreach($defaults as $key1=>$value1){
251
  ?>
252
  <option value ="<?php print($key1);?>"><?php print($key1);?></option>
253
+ <?php } $taxo = get_taxonomies();
254
+ foreach($taxo as $taxokey => $taxovalue){
255
+ if($taxokey !='category' && $taxokey !='link_category' && $taxokey != 'post_tag' && $taxokey != 'nav_menu' && $taxokey != 'post_format'){ ?>
256
+ <option value ="<?php print($taxokey);?>"><?php print($taxovalue);?></option>
257
+ <?php }
258
+ }
259
  ?>
260
  <option value="add_custom<?php print($count);?>">Add Custom Field</option>
261
  </select>
268
  </table>
269
  </div><br/>
270
  <input type='hidden' name='filename' id='filename' value="<?php echo($_FILES['csv_import']['name']);?>" />
271
+ <input type='submit' class='button-primary' name= 'post_csv' id='post_csv' value='Import' />
272
  </form>
273
  </div>
274
  <div style="min-width:45%;">
281
  </div><br/>
282
  <div style="margin-left:20px;">
283
  <form class="add:the-list: validate" method="post" action="">
284
+ <input type="submit" class="button-primary" name="Import Again" value="Import Again"/>
285
  </form>
286
  </div>
287
  <div style="margin-left:20px;margin-top:30px;">
293
  }
294
  else if(isset($_POST['post_csv']))
295
  {
296
+ $insertedRecords = 0;
297
+ $smack_taxo = array();
298
  # Code added by goku
299
  $upload_dir = wp_upload_dir();
300
  $dir = $upload_dir['basedir']."/imported_csv/";
325
  }
326
  }
327
  foreach($new_post as $ckey => $cval){
328
+ $taxo = get_taxonomies();
329
+ foreach($taxo as $taxokey => $taxovalue){
330
+ if($taxokey !='category' && $taxokey !='link_category' && $taxokey != 'post_tag' && $taxokey != 'nav_menu' && $taxokey != 'post_format'){
331
+ if($taxokey == $ckey){
332
+ $smack_taxo[$ckey] = $new_post[$ckey];
333
+ }
334
+ }
335
+ }
336
+ if($ckey!='post_category' && $ckey!='post_tag' && $ckey!='featured_image' && $ckey!= $smack_taxo[$ckey]){ // Code modified at version 2.5.0 by Fredrick Marks
337
  if(array_key_exists($ckey,$custom_array)){
338
  $darray[$ckey]=$new_post[$ckey];
339
  }
340
  else{
341
+ if(array_key_exists($ckey,$smack_taxo)){
342
+
343
+ }
344
+ else{
345
+ $data_array[$ckey]=$new_post[$ckey];
346
+ }
347
  }
348
  }
349
  else{
353
  if($ckey == 'post_category'){
354
  $categories[$ckey]=$new_post[$ckey];
355
  }
356
+ if($ckey == 'featured_image'){
357
  $file_url=$filetype[$ckey]=$new_post[$ckey];
358
  $file_type = explode('.',$filetype[$ckey]);
359
  $count = count($file_type);
380
  $filepath = $full_path.'/'.$filename[$file_split-1];
381
  $fileurl = $baseurl.'/'.$filename[$file_split-1];
382
  if(is_dir($full_path)){
383
+ $smack_fileCopy = copy($file_url,$filepath);
384
  }
385
  else{
386
  wp_mkdir_p($full_path);
387
+ $smack_fileCopy = copy($file_url,$filepath);
388
+ }
389
+ if($smack_fileCopy){
390
+ $file['guid']=$fileurl;
391
+ $file['post_title']=$img_title;
392
+ $file['post_content']='';
393
+ $file['post_status']='inherit';
394
+ }
395
+ else{
396
+ $file = false;
397
  }
 
 
 
 
398
  }
399
  }
400
  }
403
  $data_array['post_status']='draft';
404
  }
405
  $data_array['post_type']=$_POST['csv_importer_cat'];
 
 
 
 
 
 
406
 
407
+ $data_array['post_title'] = smack_marks_scandiConverter($data_array['post_title']);
408
+ $data_array['post_content'] = smack_marks_scandiConverter($data_array['post_content']);
 
 
 
 
409
 
410
+ // Duplicate Check code starts
411
+ $permission = 'notok';
412
+ $title = $data_array['post_title'];
413
+ $gettype = $data_array['post_type'];
414
+ $post_table = $wpdb->posts;
415
+ $post_exist = $wpdb->get_results("select ID from $post_table where post_title = \"{$title}\" and post_type = \"{$gettype}\" and post_status in('publish','future','draft')");
416
+ if(count($post_exist) == 0 && ($title != null || $title != '')){
417
+ $permission = 'ok';
418
+ }
419
+ // Duplicate Check code ends
420
 
421
+ if($permission == 'ok'){
422
+ $post_id = wp_insert_post( $data_array );
423
+ if($post_id){
424
+ $insertedRecords = $insertedRecords+1;
425
+ }
426
+ if(!empty($custom_array)){
427
+ foreach($custom_array as $custom_key => $custom_value){
428
+ add_post_meta($post_id, $custom_key, $custom_value);
429
+ }
430
+ }
431
+
432
+ // Create custom taxonomy to post
433
+ if(!empty($smack_taxo)){//print_r($smack_taxo);
434
+ foreach($smack_taxo as $taxo_key => $taxo_value){
435
+ $split_line = explode('|',$taxo_value);
436
+ wp_set_object_terms( $post_id, $split_line, $taxo_key );
437
+ }
438
+ } // End of code to add custom taxonomy
439
 
440
+ // Create/Add tags to post
441
+ if(!empty($tags)){
442
+ foreach($tags as $tag_key => $tag_value){
443
+ wp_set_post_tags( $post_id, $tag_value );
444
+ }
445
+ } // End of code to add tags
446
+
447
+ // Create/Add category to post
448
+ if(!empty($categories)){
449
+ $split_line = explode('|',$categories['post_category']);
450
+ wp_set_object_terms($post_id, $split_line, 'category');
451
+
452
+ } // End of code to add category
453
+
454
+ // Featured image by Fredrick Marks
455
+ if(!empty($file)){
456
+ $file_name=$dirname.'/'.$img_title.'.'.$type;
457
+ $attach_id = wp_insert_attachment($file, $file_name, $post_id);
458
+ require_once(ABSPATH . 'wp-admin/includes/image.php');
459
+ $attach_data = wp_generate_attachment_metadata( $attach_id, $fileurl );
460
+ wp_update_attachment_metadata( $attach_id, $attach_data );
461
+ set_post_thumbnail( $post_id, $attach_id );
462
+ }
463
  }
464
  }
465
  ?>
466
+ <div style="background-color: #FFFFE0;border-color: #E6DB55;border-radius: 3px 3px 3px 3px;border-style: solid;border-width: 1px;margin: 5px 15px 2px; padding: 5px;text-align:center"><b> <?php echo '('.$insertedRecords.')'; ?> records are successfully Imported ! </b></div>
467
  <div style="margin-top:30px;margin-left:10px">
468
  <form class="add:the-list: validate" method="post" enctype="multipart/form-data">
469
+ <input type="submit" class='button-primary' id="goto" name="goto" value="Continue" />
470
  </form>
471
  </div>
472
  <?php
 
 
473
  $upload_dir = wp_upload_dir();
474
  $csvdir = $upload_dir['basedir']."/imported_csv/";
475
  $CSVfile = $_POST['filename'];
476
  if(file_exists($csvdir.$CSVfile)){
 
477
  fileDelete($csvdir,$CSVfile);
478
  }
479
  }
481
  {
482
  ?>
483
  <div class="wrap">
484
+ <marquee onmouseover="this.setAttribute('scrollamount', 0, 0);" onmouseout="this.setAttribute('scrollamount', 6, 0);" >Now the <a href="http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html" target="_blank">Pro Version</a> is Available. For more details,please visit <a href="http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html" target="_blank">here</a></marquee>
485
+ <div style="background-color: #FFFFE0;border-color: #E6DB55;border-radius: 3px 3px 3px 3px;border-style: solid;border-width: 1px;margin: 5px 15px 2px; margin-top:15px;padding: 5px;text-align:center"> Please check out <a href="http://www.smackcoders.com/blog/category/free-wordpress-plugins" target="_blank">www.smackcoders.com</a> for the latest news and details of other great plugins and tools. </div><br/>
486
  <div style="min-width:45%;float:left;height:500px;">
487
+ <h2>Import CSV File</h2>
488
  <form class="add:the-list: validate" method="post" enctype="multipart/form-data" onsubmit="return file_exist();">
489
 
490
  <!-- File input -->
496
  <option value=";">;</option>
497
  </select>
498
  </p>
499
+
500
+ <p class="submit"><input type="submit" class="button-primary" name="Import" value="Import" /></p>
501
  </form>
502
  </div>
503
  <div style="min-width:45%;">