Importing IconPress icons on demo import process

You are here:
Estimated reading time: 1 min

If you’re a theme developer, you can bundle IconPress with your theme, purchasing an extended license.

IconPress is currently providing a basic method for importing the export (use IconPress > Options > Export/Backup functionality), but also a method for  One Click Demo Import plugin .

One Click Demo Import – plugin support

add_action('pt-ocdi/after_import', 'themePrefix__importIconPressData__OCDI');

function themePrefix__importIconPressData__OCDI( $import_data = array() ){

  if( empty($import_data) ){
    return;
  }

  if(class_exists('IconPress\\Helpers\\Portability')) {

    $args = array(
      'path' => '',
      'overwrite' => false
    );

    if( isset($import_data['import_file_name']) ) {
      switch( $import_data['import_file_name'] ):

        // sample data for the first demo
        case "Demo Import 1":
        $args['path'] = get_template_directory() . '/vendor/iconpress/test__1.zip';
        break;

      endswitch;
    }

    if( !file_exists($args['path']) ){
      error_log(var_export('IconPress: Couldn\'t find the import file.', 1));
    }

    $Portability = new IconPress\Helpers\Portability;

    // run import
    $import = $Portability::importIconPressData( $args );

    // check for errors
    if( isset($import['error']) ){
      error_log(var_export( 'IconPress: ' . $import['error'] , 1));
    }
    else {
      error_log(var_export('IconPress: Successfully imported the data & icons.', 1));
    }
  }
  else {
    error_log(var_export('IconPress: Couldn\'t find Portability class.', 1));
  }
}

How to implement:

  1. Rename function’s prefix eg: themePrefix__ with something custom;
  2. Copy IconPress export zip file into one of the theme’s folders, eg: my_theme/vendor/iconpress/demo1.zip . You can add as many exports as per demo;
  3. For each demo import, specify the IconPress’s path, by using a switch case, eg:
    case "Demo Import 1":
    $args['path'] = get_template_directory() . '/vendor/iconpress/test__1.zip';
    break;

    .. where case "Demo Import 1" is actually the import_file_name parameter you specify when creating a new demo import in your theme.

 

Basic sample (demo) data import

function themePrefix__importIconPressData() {

  if(class_exists('IconPress\\Helpers\\Portability')) {

    $args = array(
      // path to IconPress data zip file
      'path' => get_template_directory() . '/vendor/iconpress/demo.zip',
      // Overwrite duplicates?
      'overwrite' => false
    );

    // run import
    $Portability = new IconPress\Helpers\Portability;
    $import = $Portability::importIconPressData( $args );

    // check for errors
    if( isset($import['error']) ){
      error_log(var_export( 'IconPress: ' . $import['error'] , 1));
    }
    else {
      error_log(var_export('IconPress: Successfully imported the data & icons.', 1));
    }
  }
  else {
    error_log(var_export('IconPress: Couldn\'t find Portability class.', 1));
  }
}

// Run Import
themePrefix__importIconPressData();

How to implement:

  1. Rename function’s prefix eg: themePrefix__ with something custom;
  2. Copy IconPress export zip file into one of the theme’s folders, eg: my_theme/vendor/iconpress/demo.zip ;
  3. Specify the demo.zip’s filepath into path argument .

 

Was this article helpful?
Dislike 0
Views: 29