个性化阅读
专注于IT技术分析

WordPress,在更新/删除/创建术语时创建json文件

点击下载

从分类法” product_cat”创建/更新/删除术语时, 我必须创建一个json文件, 下面我尝试注册一个简单的json文件, 但未成功:

add_action( 'create_term', 'wpse_create_term', 10, 3 );
add_action( 'created_term', 'wpse_created_term', 10, 3 );
add_action( 'edited_term', 'wpse_edited_term', 10, 3 );
add_action( 'delete_term', 'wpse_delete_term', 10, 5 );

function wpse_create_term(){
    createJsonFile();
}

function wpse_created_term(){
    createJsonFile();
}

function wpse_edited_term(){
    createJsonFile();
}

function wpse_delete_term(){
    createJsonFile();
}

function createJsonFile(){

    echo "begin write to json file to " . dirname(__FILE__);
    $data = array("a", "b", "c", "d");
    //format the data
    $formattedData = json_encode($data);
    //set the filename
    $filename = 'members.json';
    //open or create the file
    $handle = fopen($filename, 'w+');
    //write the data into the file
    fwrite($handle, $formattedData);
    //close the file
    fclose($handle);
}

首先, 为什么这些钩子从未触发过(更新术语时未打印回显)?以及如何为最终json文件指定目标文件夹?

谢谢你的帮助。


#1


你不能从可能要使用debug.log的功能文件中回显某些内容, 其次, 你需要指定创建json文件的位置

赞(0)
未经允许不得转载:srcmini » WordPress,在更新/删除/创建术语时创建json文件

评论 抢沙发

评论前必须登录!