Title: CSV Download
Author: desie314
Published: <strong>2 Tháng 8, 2016</strong>
Last modified: 2 Tháng 8, 2016

---

Tìm kiếm plugin

Plugin này **chưa được cập nhật với 3 phiên bản mới nhất của WordPress**. Nó có 
thể không được hỗ trợ và bảo trì, và có thể xung đột với các phiên bản WordPress
mới nhất.

![](https://s.w.org/plugins/geopattern-icon/csv-download.svg)

# CSV Download

 Bởi [desie314](https://profiles.wordpress.org/desie314/)

[Tải về](https://downloads.wordpress.org/plugin/csv-download.zip)

 * [Chi tiết](https://vi.wordpress.org/plugins/csv-download/#description)
 * [Đánh giá](https://vi.wordpress.org/plugins/csv-download/#reviews)
 *  [Cài đặt](https://vi.wordpress.org/plugins/csv-download/#installation)
 * [Nhà phát triển](https://vi.wordpress.org/plugins/csv-download/#developers)

 [Hỗ trợ](https://wordpress.org/support/plugin/csv-download/)

## Mô tả

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.

    ```
    <a href="<?php echo $_SERVER["REQUEST_URI"]; ?>?csv_export_button=1">Download</a>
    ```

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](http://agencylabs.com/) – A digital production studio.

## Ảnh màn hình

[⌊Admin section example metabox.⌉⌊Admin section example metabox.⌉[

Admin section example metabox.

## Cài đặt

 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

## Đánh giá

![](https://secure.gravatar.com/avatar/9155e309b408a49e4935180198cf8ac5f6fbae6576b4b60cab34d230a81bad57?
s=60&d=retro&r=g)

### 󠀁[Heck I use it.](https://wordpress.org/support/topic/heck-i-use-it/)󠁿

 [desie314](https://profiles.wordpress.org/desie314/) 3 Tháng 9, 2016

No complaints so far.

 [ Đọc tất cả 1 đánh giá ](https://wordpress.org/support/plugin/csv-download/reviews/)

## Người đóng góp & Lập trình viên

“CSV Download” là mã nguồn mở. Những người sau đã đóng góp vào plugin này.

Những người đóng góp

 *   [ desie314 ](https://profiles.wordpress.org/desie314/)

[Dịch “CSV Download” sang ngôn ngữ của bạn.](https://translate.wordpress.org/projects/wp-plugins/csv-download)

### Muốn tham gia phát triển?

[Duyệt code](https://plugins.trac.wordpress.org/browser/csv-download/), check out
[SVN repository](https://plugins.svn.wordpress.org/csv-download/), hoặc theo dõi
[nhật ký phát triển](https://plugins.trac.wordpress.org/log/csv-download/) qua [RSS](https://plugins.trac.wordpress.org/log/csv-download/?limit=100&mode=stop_on_copy&format=rss).

## Meta

 *  Phiên bản **1.0.0**
 *  Cập nhật lần cuối **10 năm trước**
 *  Số lượt cài đặt **10+**
 *  Đã kiểm tra lên đến **4.5.33**
 *  Ngôn ngữ
 * [English (US)](https://wordpress.org/plugins/csv-download/)
 * Thẻ
 * [csv](https://vi.wordpress.org/plugins/tags/csv/)
 *  [Nâng cao](https://vi.wordpress.org/plugins/csv-download/advanced/)

## Đánh giá

 5 trên 5 sao.

 *  [  1 5-star review     ](https://wordpress.org/support/plugin/csv-download/reviews/?filter=5)
 *  [  0 4-star reviews     ](https://wordpress.org/support/plugin/csv-download/reviews/?filter=4)
 *  [  0 3-star reviews     ](https://wordpress.org/support/plugin/csv-download/reviews/?filter=3)
 *  [  0 2-star reviews     ](https://wordpress.org/support/plugin/csv-download/reviews/?filter=2)
 *  [  0 1-star reviews     ](https://wordpress.org/support/plugin/csv-download/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/csv-download/reviews/#new-post)

[Xem tất cả đánh giá](https://wordpress.org/support/plugin/csv-download/reviews/)

## Những người đóng góp

 *   [ desie314 ](https://profiles.wordpress.org/desie314/)

## Hỗ trợ

Có điều gì muốn nói? cần giúp đỡ?

 [Xem diễn đàn hỗ trợ](https://wordpress.org/support/plugin/csv-download/)