Skip to content

Instantly share code, notes, and snippets.

@mikedamage
Last active December 15, 2015 07:40
Show Gist options
  • Save mikedamage/5225532 to your computer and use it in GitHub Desktop.
Save mikedamage/5225532 to your computer and use it in GitHub Desktop.
<?php
function dm_library_document_set_file_size($pieces, $is_new_item) {
$size_val = $pieces['fields']['size']['value'];
if (!$size_val) {
$attachment = $pieces['fields']['attachment']['value'];
$attachment_id = reset($attachment);
if ($attachment_id) {
$attachment_id = $attachment_id['id'];
$file_path = get_attached_file($attachment_id);
$file_size = filesize($file_path) / 1024; // get size in kilobytes
$file_size = round($file_size, 2);
$pieces['fields']['size']['value'] = (string)$file_size;
}
}
return $pieces;
}
add_filter('pods_api_pre_save_pod_item_library_documents', 'dm_library_document_set_file_size', 10, 2);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment