[wordpress插件] CSV DownloadCSV下载

wordpress 插件 文章 2020-04-06 09:00 609 0 全屏看文

AI助手支持GPT4.0

评分
100
描述

A plugin for WP developers to easily add CSV download links to the admin section or front end.

用于WP开发人员的插件,可轻松将CSV下载链接添加到管理部分或前端。

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.

当检测到特定的GET变量(通过下载链接)时,您的数据(必须是多维数组)将传递给一个函数,该函数将其转换为csv文件并触发下载。

Add the following code to functions.php.

将以下代码添加到 functions.php

Admin Example

管理员示例

/** 

  / ** 

* Instantiate CSVDownload class with appropriate arguments (listed in class). 

*使用适当的参数实例化CSVDownload类(在类中列出)。 

* Arguments are optional 

*参数是可选的 

*/

* /

if (class_exists('CSVDownload')) {  

如果(class_exists('CSVDownload')){  

$csv_button = New CSVDownload(array(    

$ csv_button =新的CSVDownload(array(    

'post_types' => array('page'),    

'post_types'=> array('page'),    

'post_type_ids' => array(420, 114, 749),    

'post_type_ids'=> array(420,114,749),    

'metabox_title' => 'Download CSV Data',    

'metabox_title'=>'下载CSV数据',    

'help_text' => 'CSV file containing useful data.',    

'help_text'=>'包含有用数据的CSV文件。',    

'parameter' => 'csv_export_button',    

'参数'=>'csv_export_button',    

'button_text' => 'Download'  

'button_text'=>'下载'  

));

));

}

}

/** 

/ ** 

* Get results, convert to csv file, and trigger download. 

*获取结果,转换为csv文件,并触发下载。 

*/

* /

if(isset($_GET[$csv_button->parameter])) {  

if(isset($ _ GET [$ csv_button-> parameter])){  

add_action('admin_init', function(){    

add_action('admin_init',function(){    

// Get results array    

//获取结果数组    

$results = get_csv_file_results();    

$ results = get_csv_file_results();    

// Convert results array to csv file and trigger download.    

//将结果数组转换为csv文件并触发下载。    

CSVDownload::download_csv_results(array(      

CSVDownload :: download_csv_results(array(      

'results' => $results,      

'results'=> $ results,      

'file_name' => 'csv_data'    

'文件名'=>'csv_data'    

));    

));    

exit;  

出口;  

}, 1);

},1);

}

}

/** 

/ ** 

* Get the results array for the csv button download. 

*获取用于csv按钮下载的结果数组。 

* @return array 

* @返回数组 

*/

* /

function get_csv_file_results(){  

函数get_csv_file_results(){  

// Create multi-dimensional array.  

//创建多维数组。  

$results_array = array(    

$ results_array =数组(    

array('Email','User Name','Favorite Color'), // Column headers    

array('Email','User Name','Favorite Color'),//列标题    

array('fake@email.com','coolguy1','blue'),    

array('fake@email.com','coolguy1','blue'),    

array('fake@email.com','coolguy2','orange'),    

array('fake@email.com','coolguy2','orange'),    

array('fake@email.com','coolguy3','pink'),    

array('fake@email.com','coolguy3','pink'),    

array('fake@email.com','coolguy4','red'),  

array('fake@email.com','coolguy4','red'),  

);  

);  

// Return results array  

//返回结果数组  

return $results_array;

返回$ results_array;

}

}

Front End Example

前端示例

Add a button element to your HTML.

在HTML中添加按钮元素。

?csv_export_button=1">Download

  ?csv_export_button = 1“>下载

Add init action callback and provide array data.

添加初始化操作回调并提供数组数据。

/** 

  / ** 

* Get results, convert to csv file, and trigger download. 

*获取结果,转换为csv文件,并触发下载。 

*/

* /

if(isset($_GET['csv_export_button'])) {  

if(isset($ _ GET ['csv_export_button'])){  

add_action('init', function(){    

add_action('init',function(){    

// Get results array    

//获取结果数组    

$results = get_csv_file_results();    

$ results = get_csv_file_results();    

// Convert results array to csv file and trigger download.    

//将结果数组转换为csv文件并触发下载。    

CSVDownload::download_csv_results(array(      

CSVDownload :: download_csv_results(array(      

'results' => $results,      

'results'=> $ results,      

'file_name' => 'csv_data'    

'文件名'=>'csv_data'    

));    

));    

exit;  

出口;  

}, 1);

},1);

}

}

/** 

/ ** 

* Get the results array for the csv button download. 

*获取用于csv按钮下载的结果数组。 

* @return array 

* @返回数组 

*/

* /

function get_csv_file_results(){  

函数get_csv_file_results(){  

// Create multi-dimensional array.  

//创建多维数组。  

$results_array = array(    

$ results_array =数组(    

array('Email','User Name','Favorite Color'), // Column headers    

array('Email','User Name','Favorite Color'),//列标题    

array('fake@email.com','coolguy1','blue'),    

array('fake@email.com','coolguy1','blue'),    

array('fake@email.com','coolguy2','orange'),    

array('fake@email.com','coolguy2','orange'),    

array('fake@email.com','coolguy3','pink'),    

array('fake@email.com','coolguy3','pink'),    

array('fake@email.com','coolguy4','red'),  

array('fake@email.com','coolguy4','red'),  

);  

);  

// Return results array  

//返回结果数组  

return $results_array;

返回$ results_array;

}

}

AgencyLabs.com – A digital production studio.

AgencyLabs.com –数字制作工作室。

安装步骤

    1. Upload the plugin files to the /wp-content/plugins/csv-download directory, or install the plugin through the WordPress plugins screen directly.
    2. 将插件文件上传到 / wp-content / plugins / csv-download 目录,或直接通过WordPress插件屏幕安装插件。

    3. Activate the plugin through the ‘Plugins’ screen in WordPress
    4. 通过WordPress中的“插件”屏幕激活插件

下载地址
https://downloads.wordpress.org/plugin/csv-download.zip
-EOF-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
[wordpress插件] CREA Property synchronizerCREA属性同步器
[wordpress插件] Bulk Actions Select All批量操作全选
[wordpress插件] Auto Group Join自动加入群组
[wordpress插件] Index Authors page索引作者页面
[wordpress插件] Custom Post Type RSS feed自定义帖子类型RSS提要
随便看看
小程序测试号解绑之后,扫一扫小程序登录又回来了 2101
微信公众号openid? 2347
微信开放平台跟公众平台有什么区别? 3608
怎么添加小程序支付功能? 4516
教育科技公司申请微信支付被拒绝? 4798
微信公众号免300认证教程 5892
小程序已经上线,作为管理员无法在小程序数据助手查看数据? 5299
小程序广告组件通过审核,但是小程序内没有显示广告? 5067
企业微信通讯录账号被管理员误/恶意删除,怎么办? 9568
问题? 9048