【发布时间】:2019-02-22 18:40:03
【问题描述】:
我正在使用wordpress,并且我在csv 中有一个文章列表,我在php 中的函数已经在theme_options.php 文件中以及wordpress 主题的其他各种功能中工作,但我会喜欢只在后台运行注册 csv this 的函数。
我想了解如何在后台运行我的函数
我知道这是一个非常笼统的问题,但我想了解 exec 的工作原理以及我应该在什么时候在我的函数中调用它
function example() {
if( isset( $_POST['submit'] ) ) {
$lines = file(''.get_template_directory_uri() . '/list.csv', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES | FILE_TEXT);
foreach ($lines as $line_num => $line){
//some code to save csv line content
}
}
}
add_action( 'init', 'example' );
编辑
这样对吗?
csv_test.php代码:
$lines = file(''.get_template_directory_uri() . '/list.csv', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES | FILE_TEXT);
foreach ($lines as $line_num => $line){
//some code to save csv line content
}
theme_options.php代码:
function example() {
if( isset( $_POST['submit'] ) ) {
exec("php csv_test.php > /dev/null &");
}
}
add_action( 'init', 'example' );
【问题讨论】:
-
你想做什么?在高清中保存文件?
-
@Vidal 我编辑了我的问题,请参阅