Customize the AppThemes Importer

Every website is unique and has different needs. That’s why when we develop themes, we implement action hooks & filters to easily customize them without modifying core files. In this tutorial we will show you how to change some defaults of our importing tool.

Child Theme

Before starting, you will need to create a child theme. This will avoid modifying any of your core theme files while making your custom importer available on every future theme updates.

We’ve already written several tutorials on setting up and using child themes. Use them to help you get started:

What is CSV?

A comma-separated values (CSV) file stores tabular data in plain-text form. A CSV file consists of any number of records, separated by line breaks of some kind; each record consists of fields, separated by some other character or string, most commonly a literal comma or tab. Usually, all records have an identical sequence of fields.

You can find more info about CSV on Wikipedia.

Import business listings with Fax numbers

By default the Vantage importer accepts fields like address, phone, website, etc. but doesn’t support a business ‘fax’ number, and your business directory might be known from providing that information. Let’s extend importer then! We will use the Vantage filter ‘va_csv_importer_args‘ to do just this.

  1. First we need to ensure name of ‘fax’ custom field created by using Custom forms, You can find it in ‘Create Listing’ form as a field name (in our case it’s ‘app_fax‘)
  2. Now we have to add a filter into ‘functions.php‘ file of child theme, which will extend importer arguments with fax numbers
    function va_child_add_fax_field( $args ) {
      $args['custom_fields']['fax'] = array( 'internal_key' => 'app_fax' );
     
      return $args;
    }
     
    add_filter( 'va_csv_importer_args', 'va_child_add_fax_field' );
  3. As a third and last step, add ‘fax‘ column into your CSV file, example:
    title,fax,description,author,date,slug,status,address,phone,facebook,twitter,website,listing_category,listing_tag,lat,lng
    AppThemes,415-287-347,"AppThemes is a fast growing company that employs talent from all around the world.",admin,2012-04-27 00:48:56,appthemes,publish,"548 Market St, San Francisco, CA 94104, USA",415-287-3474,appthemes,appthemes,appthemes.com,Software,"themes,wordpress",37.789903,-122.400785

Don’t import coupon store descriptions

By default, the Clipper importer accepts store descriptions and override existing one. Some of us would to skip this field during importing of coupons, and add it later from WordPress back-end. We will use for this the Clipper filter ‘clpr_csv_importer_args‘.

  1. Add filter into ‘functions.php‘ file of child theme, which will remove from the importer arguments support for store description field
    function clpr_child_remove_store_desc_field( $args ) {
      unset( $args['tax_meta']['stores']['store_desc'] );
     
      return $args;
    }
     
    add_filter( 'clpr_action_importer_args', 'clpr_child_remove_store_desc_field' );
  2. Then remove ‘store_desc’ column from your CSV file (if applicable), example:
    coupon_title,coupon_description,coupon_excerpt,coupon_status,author,date,slug,coupon_code,expire_date,print_url,id,coupon_aff_url,clpr_votes_down,clpr_votes_up,clpr_votes_percent,coupon_category,coupon_tag,coupon_type,stores
    30% Off Amazon,"Great coupon from Amazon.com that gives 30% off.",,publish,1,2012-07-15 13:54:09,30-off-amazon,AMAZON30,07-04-2015,,5534f940d81c5f8e,http://www.amazon.com/?tag=20-ebt,0,0,100,Electronics,"books,electronics",Coupon Code,Amazon.com

Import ads with information about region

By default, the ClassiPress importer accept fields like street, state, country, etc. but doesn’t support a ‘region’ field, and your classified site might be local and provide that specific information. We will use for this purpose the ClassiPress filter ‘cp_csv_importer_args‘.

  1. On “ClassiPress -> Custom Fields” page you can find “meta names” of fields, for default “Region” field created by ClassiPress during Theme installation it is ‘cp_region‘.
  2. Add filter into ‘functions.php‘ file of child theme, which will extend importer arguments with ‘region‘ field
    function cp_child_add_region_field( $args ) {
      $args['custom_fields']['region'] = array( 'internal_key' => 'cp_region' );
     
      return $args;
    }
     
    add_filter( 'cp_csv_importer_args', 'cp_child_add_region_field' );
  3. Then add ‘region‘ column into your CSV file, example:
    title,region,description,status,author,date,slug,id,expire_date,duration,total_cost,price,street,city,zipcode,state,country,ad_cat,ad_tag
    ClassiPress Theme,San Francisco Bay Area,"ClassiPress is the most popular and widely used classified ads software.",publish,1,2012-07-15 13:54:09,classipress-theme,3624e0d2963459d2,07/25/2015 19:49:33,90,5.49,99,548 Market St,San Francisco,94104,California,United States,Software,"themes,wordpress"

Generate unique IDs

While importing new ads, some of you haven’t already created unique identificators, and would like to skip process of attaching them into CSV file and generate automatically during importing ads. For that purpose we will use 2 filters, ‘cp_csv_importer_args‘ to change behavior of ‘id’ parameter, and ‘app_importer_import_row_post_meta‘ to generate unique IDs.

  1. Add filter into ‘functions.php‘ file of child theme, which will set white char in ‘id‘ field by default
    function cp_child_change_id_field( $args ) {
      $args['custom_fields']['id'] = array( 'default' => ' ', 'internal_key' => 'cp_sys_ad_conf_id' );
     
      return $args;
    }
     
    add_filter( 'cp_csv_importer_args', 'cp_child_change_id_field' );
  2. Add second filter into ‘functions.php‘ file of child theme, which will find our ‘id’ field and generate for it unique identificator
    function cp_child_set_unique_id_field( $post_meta ) {
      foreach ( $post_meta as $meta_key => $meta_value ) {
        if ( $meta_key == 'cp_sys_ad_conf_id' )
          $post_meta[$meta_key] = uniqid( rand(10,1000), false );
      }
     
      return $post_meta;
    }
     
    add_filter( 'app_importer_import_row_post_meta', 'cp_child_set_unique_id_field' );
  3. Then remove ‘id’ column from your CSV file, example:
    title,description,status,author,date,slug,expire_date,duration,total_cost,price,street,city,zipcode,state,country,ad_cat,ad_tag
    ClassiPress Theme,"ClassiPress is the most popular and widely used classified ads software.",publish,1,2012-07-15 13:54:09,classipress-theme,07/25/2015 19:49:33,90,5.49,99,548 Market St,San Francisco,94104,California,United States,Software,"themes,wordpress"

Filters availability

  • cp_csv_importer_args‘ – since ClassiPress 3.2
  • clpr_csv_importer_args‘ – since Clipper 1.3
  • va_csv_importer_args‘ – since Vantage 1.0
  • app_importer_import_row_post‘ – since Vantage 1.1.3
  • app_importer_import_row_post_meta‘ – since ClassiPress 3.2, Clipper 1.3.2, Vantage 1.1
  • app_importer_import_row_after‘ – since Vantage 1.1.3

Questions?

Please use the forum for any questions or comments related with this tutorial.

Like this tutorial? Subscribe and get the latest tutorials delivered straight to your inbox or feed reader.

Your rating: none
Rating: 2.8 - 6 votes

Popular Add-ons

AutoResponder AutoRegistration

Automatically integrates WordPress registration with major autoresponders.


(5)
$39

Sorted Filtered Coupons

Sorting and Filtered Coupons on coupons listing pages as well as search…


(3)
$19

A-Z Business Listing

Inserts an A to Z listing of Business's for Vantage


(5)
$19