簡體   English   中英

從WordPress發布數據生成聯系人文件(.vcf)?

[英]Generate Contact File (.vcf) from WordPress Post Data?

創建新帖子后,我需要生成.vcf文件並將其存儲在存儲中。 保存后,我不知道該怎么辦。 沒找到開發這種功能的幫助。 請幫忙!

嘗試這個 :

在“ save_post”鈎子上,您可以編寫函數。 這將在指定目錄下創建名為post_title的.vcf文件。

function my_project_create_vCard( $post_id ) {
    $vpost = get_post($post->ID);
    $filename = strtolower(str_replace(" ","-",$vpost->post_title)).".vcf";
    header('Content-type: text/x-vcard; charset=utf-8');
    header("Content-Disposition: attachment; filename=".$filename);
    $data=null;
    $data.="BEGIN:VCARD\n";
    $data.="VERSION:2.1\n";
    $data.="FN:".$vpost->post_title."\n"; // get post title
    $data.="EMAIL:" .get_field('email',$vpost->ID)."\n";  // get acf field value
    $data.="END:VCARD";
    $filePath = get_template_directory()."/".$filename; // you can specify path here where you want to store file.
    $file = fopen($filePath,"w");
    fwrite($file,$data);
    fclose($file);
}
add_action( 'save_post', 'my_project_create_vCard' );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM