Last active
June 25, 2018 17:00
-
-
Save verygoodplugins/12d5a4988bcbae79ecd79a20d65d7334 to your computer and use it in GitHub Desktop.
Shows Infusionsoft filebox files for a contact on the admin user profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function process_file_download() { | |
if( ! isset( $_GET['ifs_download'] ) || empty( $_GET['ifs_download'] ) || ! is_user_logged_in() ) { | |
return; | |
} | |
$file_id = $_GET['ifs_download']; | |
wp_fusion()->crm->connect(); | |
$file = wp_fusion()->crm->app->getFile( $file_id ); | |
header('Content-Description: File Transfer'); | |
header("Content-type: application/octet-stream"); | |
header("Content-disposition: attachment; filename= " . urldecode( $_GET['name'] ) ); | |
exit( base64_decode( $file ) ); | |
} | |
add_action( 'init', 'process_file_download' ); | |
function user_profile_filebox( $user ) { | |
$contact_id = wp_fusion()->user->get_contact_id( $user->ID ); | |
if( empty( $contact_id ) ) { | |
return; | |
} | |
wp_fusion()->crm->connect(); | |
$fields = array( 'FileName', 'Id' ); | |
$query = array( 'ContactId' => $contact_id ); | |
$files = wp_fusion()->crm->app->dsQuery( 'FileBox', 1000, 0, $query, $fields ); | |
if( empty( $files ) ) { | |
return; | |
} | |
?> | |
<table class="form-table"> | |
<tr> | |
<th><label for="files"><?php echo wp_fusion()->crm->name ?> Files</label></th> | |
<td id="files"> | |
<ul> | |
<?php foreach( $files as $file ) : ?> | |
<li><a href="<?php echo home_url() ?>/?ifs_download=<?php echo $file['Id'] ?>&name=<?php echo urlencode( $file['FileName'] ); ?>" target="_blank"><?php echo $file['FileName']; ?></a></li> | |
<?php endforeach; ?> | |
</ul> | |
</td> | |
</tr> | |
</table> | |
<?php | |
} | |
add_action( 'show_user_profile', 'user_profile_filebox' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment