Changeset 1152758
- Timestamp:
- 05/04/2015 10:07:56 AM (11 years ago)
- Location:
- really-simple-csv-importer/trunk
- Files:
-
- 3 added
- 3 edited
-
class-rscsv_import_post_helper.php (modified) (5 diffs)
-
readme.txt (modified) (7 diffs)
-
rs-csv-importer.php (modified) (3 diffs)
-
sample/post_status_test.csv (added)
-
sample/smart_custom_fields.csv (added)
-
sample/smart_custom_fields.ods (added)
Legend:
- Unmodified
- Added
- Removed
-
really-simple-csv-importer/trunk/class-rscsv_import_post_helper.php
r1079946 r1152758 9 9 { 10 10 const CFS_PREFIX = 'cfs_'; 11 const SCF_PREFIX = 'scf_'; 11 12 12 13 /** … … 142 143 public function setMeta($data) 143 144 { 145 $scf_array = array(); 144 146 foreach ($data as $key => $value) { 145 147 $is_cfs = 0; 148 $is_scf = 0; 146 149 $is_acf = 0; 147 150 if (strpos($key, self::CFS_PREFIX) === 0) { 148 151 $this->cfsSave(substr($key, strlen(self::CFS_PREFIX)), $value); 149 152 $is_cfs = 1; 153 } elseif(strpos($key, self::SCF_PREFIX) === 0) { 154 $scf_key = substr($key, strlen(self::SCF_PREFIX)); 155 $scf_array[$scf_key][] = $value; 156 $is_scf = 1; 150 157 } else { 151 158 if (function_exists('get_field_object')) { … … 159 166 } 160 167 } 161 if (!$is_acf && !$is_cfs ) {168 if (!$is_acf && !$is_cfs && !$is_scf) { 162 169 $this->updateMeta($key, $value); 163 170 } 164 171 } 172 $this->scfSave($scf_array); 165 173 } 166 174 … … 204 212 * A wrapper of CFS()->save() 205 213 * 206 * @param (array) $data 214 * @param (string) $key 215 * @param (string/array) $value 207 216 */ 208 217 protected function cfsSave($key, $value) … … 216 225 } else { 217 226 $this->updateMeta($key, $value); 227 } 228 } else { 229 $this->addError('post_is_not_set', __('WP_Post object is not set.', 'really-simple-csv-importer')); 230 } 231 } 232 233 /** 234 * A wrapper of Smart_Custom_Fields_Meta()->save() 235 * 236 * @param (array) $data 237 */ 238 protected function scfSave($data) 239 { 240 $post = $this->getPost(); 241 if ($post instanceof WP_Post) { 242 if (class_exists('Smart_Custom_Fields_Meta') && is_array($data)) { 243 $_data = array(); 244 $_data['smart-custom-fields'] = $data; 245 $meta = new Smart_Custom_Fields_Meta($post); 246 $meta->save($_data); 247 } elseif(is_array($data)) { 248 foreach ($data as $key => $array) { 249 foreach ((array) $array as $value) { 250 $this->updateMeta($key, $value); 251 } 252 } 218 253 } 219 254 } else { -
really-simple-csv-importer/trunk/readme.txt
r1079946 r1152758 1 1 === Really Simple CSV Importer === 2 2 Contributors: hissy 3 Tags: importer, csv, acf, cfs 3 Tags: importer, csv, acf, cfs, scf 4 4 Requires at least: 3.6 5 Tested up to: 4. 16 Stable tag: 1. 15 Tested up to: 4.2.1 6 Stable tag: 1.2 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 17 17 * Tag support 18 18 * Custom field support 19 * [Smart Custom Fields](https://wordpress.org/plugins/smart-custom-fields/) support 19 20 * [Custom Field Suite](http://customfieldsuite.com/) support 20 21 * [Advanced Custom Fields](http://www.advancedcustomfields.com/) support … … 46 47 * `tax_{taxonomy}`: (string, comma separated) Any field prefixed with `tax_` will be used as a custom taxonomy. Taxonomy must already exist. Entries are names or slugs of terms. 47 48 * `{custom_field_key}`: (string) Any other column labels used as custom field 48 * `cfs_{field_name}`: (string) If you would like to import data to custom fields set by Custom Field Suite, please add prefix `cfs_` 49 * `cfs_{field_name}`: (string) If you would like to import data to custom fields set by Custom Field Suite, please add prefix `cfs_` to column header name. 50 * `scf_{field_name}`: (string) If you would like to import data to custom fields set by Smart Custom Fields, please add prefix `scf_` to column header name. 49 51 50 52 Note: Empty cells in the csv file means "keep it", not "delete it". … … 87 89 Yes. You can use column names same as wp_post table, but if the column name does not match, it creates a custom field (post meta) data. Importing custom taxonomy is a bit more complicated, "tax_{taxonomy}" means, "tax_" is prefix, and {taxonomy} is name of custom taxonomy (not labels). 88 90 89 Here is a example.91 Here is an example. 90 92 91 93 **csv file** … … 106 108 = Can I insert multiple values to CFS or ACF fields like Select or Checkbox? = 107 109 108 Yes. Please use `really_simple_csv_importer_save_meta` filter to make array data. 110 Yes. Please create additional plugin and use `really_simple_csv_importer_save_meta` filter to make array data. 111 112 [Add-on development example](https://gist.github.com/hissy/d2041481a72510b7f394) 109 113 110 114 == How to debug import data == … … 211 215 This action provides availability to run some tasks after importing. 212 216 213 Example: [gist](https://gist.github.com/hissy/fe0aa2582b78394a3a82)217 Example: Download image from remote url to custom field (Download from [gist](https://gist.github.com/hissy/0973a6a9977129a6ebd0)) 214 218 215 219 == How to customize the importing process entirely == … … 219 223 This filter provides availability to completely replace the `RS_CSV_Importer#save_post` method. 220 224 221 Example: [gist](https://gist.github.com/hissy/199ad9be855ec9be1e54)225 Example: Update row based on a custom field ID/key match (Download from [gist](https://gist.github.com/hissy/199ad9be855ec9be1e54)) 222 226 223 227 == Changelog == 224 228 229 = 1.2 = 230 * Enhancement: Smart Custom Fields support 231 * Check if the provided post status is already registered 225 232 = 1.1 = 226 233 * Enhancement: Support localization -
really-simple-csv-importer/trunk/rs-csv-importer.php
r1079946 r1152758 8 8 Text Domain: really-simple-csv-importer 9 9 License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 10 Version: 1. 110 Version: 1.2 11 11 */ 12 12 … … 152 152 153 153 $is_first = true; 154 $post_statuses = get_post_stati(); 154 155 155 156 echo '<ol>'; … … 224 225 $post_status = $h->get_data($this,$data,'post_status'); 225 226 if ($post_status) { 226 $post['post_status'] = $post_status; 227 if (in_array($post_status, $post_statuses)) { 228 $post['post_status'] = $post_status; 229 } 227 230 } 228 231
Note: See TracChangeset
for help on using the changeset viewer.