Plugin info

Total downloads: 1,085
Active installs: 10
Total reviews: 1
Average rating: 5
Support threads opened: 0
Support threads resolved: 0 (0%)
Available in: 1 language(s)
Contributors: 1
Last updated: 8/2/2016 (3493 days ago)
Added to WordPress: 8/2/2016 (9 years old)
Minimum WordPress version: f
Tested up to WordPress version: 4.5.28
Minimum PHP version: f

Maintenance & Compatibility

Maintenance score

Possibly abandoned • Last updated 3493 days ago • 1 reviews

22/100

Is CSV Download abandoned?

Possibly abandoned (last update 3493 days ago).

Compatibility

Requires WordPress: f
Tested up to: 4.5.28
Requires PHP: f

Languages

Similar & Alternatives

Explore plugins with similar tags, and compare key metrics like downloads, ratings, updates, support, and WP/PHP compatibility.

No similar plugins found yet.

Description

A plugin for WP developers to easily add CSV download links to the admin section or front end. When a specific GET variable is detected (from the download link) your data, which needs to be a multi-dimensional array, is passed to a function that converts it to a csv file and triggers the download.

Add the following code to functions.php.

Admin Example

/**
 * Instantiate CSVDownload class with appropriate arguments (listed in class).
 * Arguments are optional
 */
if (class_exists('CSVDownload')) {
  $csv_button = New CSVDownload(array(
    'post_types' => array('page'),
    'post_type_ids' => array(420, 114, 749),
    'metabox_title' => 'Download CSV Data',
    'help_text' => 'CSV file containing useful data.',
    'parameter' => 'csv_export_button',
    'button_text' => 'Download'
  ));
}

/**
 * Get results, convert to csv file, and trigger download.
 */
if(isset($_GET[$csv_button->parameter])) {
  add_action('admin_init', function(){
    // Get results array
    $results = get_csv_file_results();
    // Convert results array to csv file and trigger download.
    CSVDownload::download_csv_results(array(
      'results' => $results,
      'file_name' => 'csv_data'
    ));
    exit;
  }, 1);
}

/**
 * Get the results array for the csv button download.
 *
 * @return array
 */
function get_csv_file_results(){

  // Create multi-dimensional array.
  $results_array = array(
    array('Email','User Name','Favorite Color'), // Column headers
    array('[email protected]','coolguy1','blue'),
    array('[email protected]','coolguy2','orange'),
    array('[email protected]','coolguy3','pink'),
    array('[email protected]','coolguy4','red'),
  );

  // Return results array
  return $results_array;
}

Front End Example

Add a button element to your HTML.

?csv_export_button=1">Download

Add init action callback and provide array data.

/**
 * Get results, convert to csv file, and trigger download.
 */
if(isset($_GET['csv_export_button'])) {
  add_action('init', function(){
    // Get results array
    $results = get_csv_file_results();
    // Convert results array to csv file and trigger download.
    CSVDownload::download_csv_results(array(
      'results' => $results,
      'file_name' => 'csv_data'
    ));
    exit;
  }, 1);
}

/**
 * Get the results array for the csv button download.
 *
 * @return array
 */
function get_csv_file_results(){

  // Create multi-dimensional array.
  $results_array = array(
    array('Email','User Name','Favorite Color'), // Column headers
    array('[email protected]','coolguy1','blue'),
    array('[email protected]','coolguy2','orange'),
    array('[email protected]','coolguy3','pink'),
    array('[email protected]','coolguy4','red'),
  );

  // Return results array
  return $results_array;
}

AgencyLabs.com – A digital production studio.

Installation

  1. Upload the plugin files to the /wp-content/plugins/csv-download directory, or install the plugin through the WordPress plugins screen directly.
  2. Activate the plugin through the ‘Plugins’ screen in WordPress

Frequently Asked Questions

No FAQ available

Review feed

desie314
9/3/2016

Heck I use it.

No complaints so far.

Screenshots

  1. Admin section example metabox.

    Admin section example metabox.

Changelog

No changelog available