• Best Drag & Drop Website Builder
  • Build Any Type of Website
  • Unlimited design flexibility
  • Drag & Drop Builder

CSV Download

by Desmond O’Grady

1 Ratings

  • 5.0

Active Installations

10+

Last Update

8 years

Quality

D

Plugin Description

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(‘fake@email.com’,’coolguy1′,’blue’),
array(‘fake@email.com’,’coolguy2′,’orange’),
array(‘fake@email.com’,’coolguy3′,’pink’),
array(‘fake@email.com’,’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(‘fake@email.com’,’coolguy1′,’blue’),
array(‘fake@email.com’,’coolguy2′,’orange’),
array(‘fake@email.com’,’coolguy3′,’pink’),
array(‘fake@email.com’,’coolguy4′,’red’),
);

// Return results array
return $results_array;
}
AgencyLabs.com – A digital production studio.

Similar Plugins

The content on this website originates from various sources. All rights to the original content remain with the respective author. If you believe that your copyrights have been infringed by the use of content on this website, please contact us at info@plugin-guru.com. We will remove the content in question immediately.

This is the heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Collections

Create your first Collection

To create a collection, simply click on the symbol on the desired plugin.

You can see this symbol when you move the mouse over the plugin. 

Current Level

Plugin Magican

You have reached 0 views on your collections and are currently Plugin Magican. You magically help people find the right plugins and are a great asset to the community

0 of 500 views reached