Title: CSV Download
Author: desie314
Published: <strong>2016 年 8 月 2 日</strong>
Last modified: 2016 年 8 月 2 日

---

搜尋外掛

這個外掛**並未在最新的 3 個 WordPress 主要版本上進行測試**。開發者可能不再對這個
外掛進行維護或提供技術支援，並可能會與更新版本的 WordPress 產生使用上的相容性問題。

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

# CSV Download

 由 [desie314](https://profiles.wordpress.org/desie314/) 開發

[下載](https://downloads.wordpress.org/plugin/csv-download.zip)

 * [詳細資料](https://tw.wordpress.org/plugins/csv-download/#description)
 * [使用者評論](https://tw.wordpress.org/plugins/csv-download/#reviews)
 *  [安裝方式](https://tw.wordpress.org/plugins/csv-download/#installation)
 * [開發資訊](https://tw.wordpress.org/plugins/csv-download/#developers)

 [技術支援](https://wordpress.org/support/plugin/csv-download/)

## 外掛說明

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.

## 螢幕擷圖

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

Admin section example metabox.

## 安裝方式

 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

## 使用者評論

![](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/) 2016 年 9 月 3 日

No complaints so far.

 [ 閱讀全部 1 則使用者評論 ](https://wordpress.org/support/plugin/csv-download/reviews/)

## 參與者及開發者

以下人員參與了開源軟體〈CSV Download〉的開發相關工作。

參與者

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

[將〈CSV Download〉外掛本地化為台灣繁體中文版](https://translate.wordpress.org/projects/wp-plugins/csv-download)

### 對開發相關資訊感興趣？

任何人均可[瀏覽程式碼](https://plugins.trac.wordpress.org/browser/csv-download/)、
查看 [SVN 存放庫](https://plugins.svn.wordpress.org/csv-download/)，或透過 [RSS](https://plugins.trac.wordpress.org/log/csv-download/?limit=100&mode=stop_on_copy&format=rss)
訂閱[開發記錄](https://plugins.trac.wordpress.org/log/csv-download/)。

## 中繼資料

 *  版本 **1.0.0**
 *  最後更新 **10 年前**
 *  啟用安裝數 **10+**
 *  已測試相容的 WordPress 版本 **4.5.33**
 *  語言
 * [English (US)](https://wordpress.org/plugins/csv-download/)
 * 標籤:
 * [csv](https://tw.wordpress.org/plugins/tags/csv/)
 *  [進階檢視](https://tw.wordpress.org/plugins/csv-download/advanced/)

## 評分

 5 星，滿分為 5 星

 *  [  1 個 5 星使用者評論     ](https://wordpress.org/support/plugin/csv-download/reviews/?filter=5)
 *  [  0 個 4 星使用者評論     ](https://wordpress.org/support/plugin/csv-download/reviews/?filter=4)
 *  [  0 個 3 星使用者評論     ](https://wordpress.org/support/plugin/csv-download/reviews/?filter=3)
 *  [  0 個 2 星使用者評論     ](https://wordpress.org/support/plugin/csv-download/reviews/?filter=2)
 *  [  0 個 1 星使用者評論     ](https://wordpress.org/support/plugin/csv-download/reviews/?filter=1)

[撰寫評分](https://wordpress.org/support/plugin/csv-download/reviews/#new-post)

[查看全部使用者評論](https://wordpress.org/support/plugin/csv-download/reviews/)

## 參與者

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

## 技術支援

使用者可在技術支援論壇提出意見反應或使用問題。

 [檢視技術支援論壇](https://wordpress.org/support/plugin/csv-download/)