This creates a .vcf file from the post types.
Create a VCard For Brokers (this was first built for Mericle) Return the last segment of the URI
This feature works by creating/modifying a vcf file when a broker post type is saved. the template then points to that saved file. File will not create if you don't Save/Update the post type.
@TODO To complete this, you need to create a '/vcard' folder in your template directory.
Also add the following code to link where it lives.
<?php
/**
* Create a VCard For Brokers (this was first built for Mericle)
* Return the last segment of the URI
*
*
* This feature works by creating/modifying a vcf file when a broker post type is saved. the template then points to that saved file.
* File will not create if you don't Save/Update the post type.
*
* @TODO To complete this, you need to create a '/vcard' folder in your template directory.
*
* Also - add the following code to link where it lives:
*
*
*
* <?php
* $vcfname = $post->post_name;
* $uploadfile = wp_get_upload_dir();
* $uploadfile = $uploadfile["basedir"]."/vcard/";
* ?>
* <a href="<?php echo $uploadfile ?><?php echo $vcfname; ?>.vcf" download><i * class="team-hero__social-link--vcard"></i> Download Vcard</a>
*/
function create_vCard( $post_id ) {
$post_type = get_post_type($post_id);
// Should only action if 'brokers' post type is saved
if ( "brokers" != $post_type ) return;
$id = get_the_ID();
$thumbnailid = get_post_thumbnail_id($post_id, 'medium');
$img = ( get_attached_file( $thumbnailid ) );
$img = file_get_contents($img);
$imgencode = base64_encode( $img );
$vpost = get_post($post->ID);
$filename = $vpost->post_name.".vcf";
header('Content-type: text/x-vcard; charset=utf-8');
header("Content-Disposition: attachment; filename=".$filename);
$data=null;
$data.="BEGIN:VCARD\n";
$data.="VERSION:3.0\n";
$data.="FN:".$post->post_title."\n";
$data.="TITLE:" .get_field('position',$id)."\n";
$data.="ORG:Mericle Commercial Real Estate Group\n";
$data.="EMAIL;PREF;INTERNET:" .get_field('email',$id)."\n";
$data.="TEL;WORK;VOICE:" .get_field('phone',$id)."\n";
$data.="TEL;CELL;VOICE:" .get_field('cellphone',$id)."\n";
$data.="TEL;WORK;FAX:" .get_field('faxnumber',$id)."\n";
$data.="ADR;WORK;PREF:".get_field('address',$id)."\n";
$data.="URL;WORK:www.mericle.com"."\n";
$data.="EMAIL;PREF;INTERNET:" .get_field('email',$id)."\n";
$data.="PHOTO;TYPE=JPEG;ENCODING=BASE64:".$imgencode."\n\n\n";
$data.='X-MS-OL-DESIGN;CHARSET=utf-8:<card xmlns="http://schemas.microsoft.com/office/outlook/12/electronicbusinesscards" ver="1.0" layout="left" bgcolor="ffffff"><img xmlns="" align="tleft" area="32" use="photo"/><fld xmlns="" prop="name" align="left" dir="ltr" style="b" color="000000" size="10"/><fld xmlns="" prop="org" align="left" dir="ltr" color="000000" size="8"/><fld xmlns="" prop="title" align="left" dir="ltr" color="000000" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="telwork" align="left" dir="ltr" color="000000" size="8"><label align="right" color="626262">Work</label></fld><fld xmlns="" prop="email" align="left" dir="ltr" color="000000" size="8"/><fld xmlns="" prop="addrwork" align="left" dir="ltr" color="000000" size="8"/><fld xmlns="" prop="webwork" align="left" dir="ltr" color="000000" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/></card>';
$data.="END:VCARD";
$filePath = wp_upload_dir()["basedir"].'/vcard/'.$filename;
$file = fopen($filePath,"w");
fwrite($file,$data);
fclose($file);
}
add_action( 'save_post', 'create_vCard' );
<?php
$vcfname = $post->post_name;
$uploadfile = wp_get_upload_dir();
$uploadfile = $uploadfile["basedir"]."/vcard/";
?>
<a href="<?php echo $uploadfile ?><?php echo $vcfname; ?>.vcf" download><i class="team-hero__social-link--vcard"></i> Download Vcard</a>