{"id":50008,"date":"2016-08-02T13:48:49","date_gmt":"2016-08-02T13:48:49","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/csv-download\/"},"modified":"2016-08-02T18:36:46","modified_gmt":"2016-08-02T18:36:46","slug":"csv-download","status":"publish","type":"plugin","link":"https:\/\/da.wordpress.org\/plugins\/csv-download\/","author":8476511,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"1.0.0","stable_tag":"trunk","tested":"4.5.33","requires":"","requires_php":"","requires_plugins":"","header_name":"CSVDownload","header_author":"Desmond O'Grady","header_description":"","assets_banners_color":"","last_updated":"2016-08-02 18:36:46","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"","header_author_uri":"","rating":5,"author_block_rating":0,"active_installs":10,"downloads":1885,"num_ratings":1,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation"],"tags":[],"upgrade_notice":[],"ratings":{"1":0,"2":0,"3":0,"4":0,"5":"1"},"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":[],"block_files":[],"assets_screenshots":{"screenshot-1.png":{"filename":"screenshot-1.png","revision":"1539332","resolution":"1","location":"plugin","width":1532,"height":383}},"screenshots":{"1":"Admin section example metabox."},"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[75292,567,75289,75291,75290],"plugin_category":[],"plugin_contributors":[95480],"plugin_business_model":[],"class_list":["post-50008","plugin","type-plugin","status-publish","hentry","plugin_tags-comma-separated-values-list","plugin_tags-csv","plugin_tags-csv-download","plugin_tags-csv-download-button","plugin_tags-csv-download-link","plugin_contributors-desie314","plugin_committers-desie314"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/csv-download.svg","icon_2x":false,"generated":true},"screenshots":[{"src":"https:\/\/ps.w.org\/csv-download\/trunk\/screenshot-1.png?rev=1539332","caption":"Admin section example metabox."}],"raw_content":"<!--section=description-->\n<p>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.<\/p>\n\n<p>Add the following code to <strong>functions.php<\/strong>.<\/p>\n\n<h4>Admin Example<\/h4>\n\n<pre><code>\/**\n * Instantiate CSVDownload class with appropriate arguments (listed in class).\n * Arguments are optional\n *\/\nif (class_exists('CSVDownload')) {\n  $csv_button = New CSVDownload(array(\n    'post_types' =&gt; array('page'),\n    'post_type_ids' =&gt; array(420, 114, 749),\n    'metabox_title' =&gt; 'Download CSV Data',\n    'help_text' =&gt; 'CSV file containing useful data.',\n    'parameter' =&gt; 'csv_export_button',\n    'button_text' =&gt; 'Download'\n  ));\n}\n\n\/**\n * Get results, convert to csv file, and trigger download.\n *\/\nif(isset($_GET[$csv_button-&gt;parameter])) {\n  add_action('admin_init', function(){\n    \/\/ Get results array\n    $results = get_csv_file_results();\n    \/\/ Convert results array to csv file and trigger download.\n    CSVDownload::download_csv_results(array(\n      'results' =&gt; $results,\n      'file_name' =&gt; 'csv_data'\n    ));\n    exit;\n  }, 1);\n}\n\n\/**\n * Get the results array for the csv button download.\n *\n * @return array\n *\/\nfunction get_csv_file_results(){\n\n  \/\/ Create multi-dimensional array.\n  $results_array = array(\n    array('Email','User Name','Favorite Color'), \/\/ Column headers\n    array('fake@email.com','coolguy1','blue'),\n    array('fake@email.com','coolguy2','orange'),\n    array('fake@email.com','coolguy3','pink'),\n    array('fake@email.com','coolguy4','red'),\n  );\n\n  \/\/ Return results array\n  return $results_array;\n}\n<\/code><\/pre>\n\n<h4>Front End Example<\/h4>\n\n<p>Add a button element to your HTML.<\/p>\n\n<pre><code>&lt;a href=\"&lt;?php echo $_SERVER[\"REQUEST_URI\"]; ?&gt;?csv_export_button=1\"&gt;Download&lt;\/a&gt;\n<\/code><\/pre>\n\n<p>Add init action callback and provide array data.<\/p>\n\n<pre><code>\/**\n * Get results, convert to csv file, and trigger download.\n *\/\nif(isset($_GET['csv_export_button'])) {\n  add_action('init', function(){\n    \/\/ Get results array\n    $results = get_csv_file_results();\n    \/\/ Convert results array to csv file and trigger download.\n    CSVDownload::download_csv_results(array(\n      'results' =&gt; $results,\n      'file_name' =&gt; 'csv_data'\n    ));\n    exit;\n  }, 1);\n}\n\n\/**\n * Get the results array for the csv button download.\n *\n * @return array\n *\/\nfunction get_csv_file_results(){\n\n  \/\/ Create multi-dimensional array.\n  $results_array = array(\n    array('Email','User Name','Favorite Color'), \/\/ Column headers\n    array('fake@email.com','coolguy1','blue'),\n    array('fake@email.com','coolguy2','orange'),\n    array('fake@email.com','coolguy3','pink'),\n    array('fake@email.com','coolguy4','red'),\n  );\n\n  \/\/ Return results array\n  return $results_array;\n}\n<\/code><\/pre>\n\n<p><a href=\"http:\/\/agencylabs.com\/\">AgencyLabs.com<\/a> - A digital production studio.<\/p>\n\n<!--section=installation-->\n<ol>\n<li>Upload the plugin files to the <code>\/wp-content\/plugins\/csv-download<\/code> directory, or install the plugin through the WordPress plugins screen directly.<\/li>\n<li>Activate the plugin through the 'Plugins' screen in WordPress<\/li>\n<\/ol>","raw_excerpt":"A plugin for WP developers to easily add CSV download links to the admin section or front end.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/da.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/50008","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/da.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/da.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/da.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=50008"}],"author":[{"embeddable":true,"href":"https:\/\/da.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/desie314"}],"wp:attachment":[{"href":"https:\/\/da.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=50008"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/da.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=50008"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/da.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=50008"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/da.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=50008"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/da.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=50008"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/da.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=50008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}