Plugin Directory

Changeset 1152758


Ignore:
Timestamp:
05/04/2015 10:07:56 AM (11 years ago)
Author:
hissy
Message:

Squashed commit

Location:
really-simple-csv-importer/trunk
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • really-simple-csv-importer/trunk/class-rscsv_import_post_helper.php

    r1079946 r1152758  
    99{
    1010    const CFS_PREFIX = 'cfs_';
     11    const SCF_PREFIX = 'scf_';
    1112   
    1213    /**
     
    142143    public function setMeta($data)
    143144    {
     145        $scf_array = array();
    144146        foreach ($data as $key => $value) {
    145147            $is_cfs = 0;
     148            $is_scf = 0;
    146149            $is_acf = 0;
    147150            if (strpos($key, self::CFS_PREFIX) === 0) {
    148151                $this->cfsSave(substr($key, strlen(self::CFS_PREFIX)), $value);
    149152                $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;
    150157            } else {
    151158                if (function_exists('get_field_object')) {
     
    159166                }
    160167            }
    161             if (!$is_acf && !$is_cfs) {
     168            if (!$is_acf && !$is_cfs && !$is_scf) {
    162169                $this->updateMeta($key, $value);
    163170            }
    164171        }
     172        $this->scfSave($scf_array);
    165173    }
    166174   
     
    204212     * A wrapper of CFS()->save()
    205213     *
    206      * @param (array) $data
     214     * @param (string) $key
     215     * @param (string/array) $value
    207216     */
    208217    protected function cfsSave($key, $value)
     
    216225            } else {
    217226                $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                }
    218253            }
    219254        } else {
  • really-simple-csv-importer/trunk/readme.txt

    r1079946 r1152758  
    11=== Really Simple CSV Importer ===
    22Contributors: hissy
    3 Tags: importer, csv, acf, cfs
     3Tags: importer, csv, acf, cfs, scf
    44Requires at least: 3.6
    5 Tested up to: 4.1
    6 Stable tag: 1.1
     5Tested up to: 4.2.1
     6Stable tag: 1.2
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1717* Tag support
    1818* Custom field support
     19* [Smart Custom Fields](https://wordpress.org/plugins/smart-custom-fields/) support
    1920* [Custom Field Suite](http://customfieldsuite.com/) support
    2021* [Advanced Custom Fields](http://www.advancedcustomfields.com/) support
     
    4647* `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.
    4748* `{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.
    4951
    5052Note: Empty cells in the csv file means "keep it", not "delete it". 
     
    8789Yes. 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).
    8890
    89 Here is a example.
     91Here is an example.
    9092
    9193**csv file** 
     
    106108= Can I insert multiple values to CFS or ACF fields like Select or Checkbox? =
    107109
    108 Yes. Please use `really_simple_csv_importer_save_meta` filter to make array data.
     110Yes. 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)
    109113
    110114== How to debug import data ==
     
    211215This action provides availability to run some tasks after importing.
    212216
    213 Example: [gist](https://gist.github.com/hissy/fe0aa2582b78394a3a82)
     217Example: Download image from remote url to custom field (Download from [gist](https://gist.github.com/hissy/0973a6a9977129a6ebd0))
    214218
    215219== How to customize the importing process entirely ==
     
    219223This filter provides availability to completely replace the `RS_CSV_Importer#save_post` method.
    220224
    221 Example: [gist](https://gist.github.com/hissy/199ad9be855ec9be1e54)
     225Example: Update row based on a custom field ID/key match (Download from [gist](https://gist.github.com/hissy/199ad9be855ec9be1e54))
    222226
    223227== Changelog ==
    224228
     229= 1.2 =
     230* Enhancement: Smart Custom Fields support
     231* Check if the provided post status is already registered
    225232= 1.1 =
    226233* Enhancement: Support localization
  • really-simple-csv-importer/trunk/rs-csv-importer.php

    r1079946 r1152758  
    88Text Domain: really-simple-csv-importer
    99License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    10 Version: 1.1
     10Version: 1.2
    1111*/
    1212
     
    152152       
    153153        $is_first = true;
     154        $post_statuses = get_post_stati();
    154155       
    155156        echo '<ol>';
     
    224225                $post_status = $h->get_data($this,$data,'post_status');
    225226                if ($post_status) {
    226                     $post['post_status'] = $post_status;
     227                    if (in_array($post_status, $post_statuses)) {
     228                        $post['post_status'] = $post_status;
     229                    }
    227230                }
    228231               
Note: See TracChangeset for help on using the changeset viewer.